@Test public void shouldLockAtLeastFor() throws InterruptedException { // Lock for LOCK_AT_LEAST_FOR - we do not expect the lock to be released before this time Optional<SimpleLock> lock1 = getLockProvider().lock(lockConfig(LOCK_NAME1, LOCK_AT_LEAST_FOR.multipliedBy(2), LOCK_AT_LEAST_FOR)); assertThat(lock1).isNotEmpty(); lock1.get().unlock(); // Even though we have unlocked the lock, it will be held for some time assertThat(getLockProvider().lock(lockConfig(LOCK_NAME1))).describedAs("Can not acquire lock, grace period did not pass yet").isEmpty(); // Let's wait wor the lock to be automatically released sleep(LOCK_AT_LEAST_FOR.toMillis()); // Should be able to acquire now Optional<SimpleLock> lock3 = getLockProvider().lock(lockConfig(LOCK_NAME1)); assertThat(lock3).describedAs("Can acquire the lock after grace period").isNotEmpty(); lock3.get().unlock(); }
@Test public void runTestCase() throws Exception { boolean shouldIgnore = Cases.shouldIgnore(endpointName, jsonString); System.out.println(String.format("[%s%s test case %s]: %s(%s), expected client to %s", shouldIgnore ? "ignored " : "", shouldSucceed ? "positive" : "negative", index, endpointName, jsonString, shouldSucceed ? "succeed" : "fail")); Optional<Error> expectationFailure = shouldSucceed ? expectSuccess() : expectFailure(); if (shouldIgnore) { assertThat(expectationFailure).describedAs( "The test passed but the test case was ignored - remove this from ignored-test-cases.yml") .isNotEmpty(); } Assume.assumeFalse(shouldIgnore); if (expectationFailure.isPresent()) { throw expectationFailure.get(); } }
@Test @SuppressWarnings("IllegalThrows") public void runTestCase() throws Error, NoSuchMethodException { boolean shouldIgnore = Cases.shouldIgnore(endpointName, jsonString); Method method = testService.getClass().getMethod(endpointName.get(), int.class); System.out.println(String.format("[%s%s test case %s]: %s(%s), expected client to %s", shouldIgnore ? "ignored " : "", shouldSucceed ? "positive" : "negative", index, endpointName, jsonString, shouldSucceed ? "succeed" : "fail")); Optional<Error> expectationFailure = shouldSucceed ? expectSuccess(method) : expectFailure(method); if (shouldIgnore) { assertThat(expectationFailure).describedAs( "The test passed but the test case was ignored - remove this from ignored-test-cases.yml") .isNotEmpty(); } Assume.assumeFalse(shouldIgnore); if (expectationFailure.isPresent()) { throw expectationFailure.get(); } }