Skip to content

Commit

Permalink
Invalid assertion in LastExecutionTests
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAure committed Oct 4, 2023
1 parent 1ab15d4 commit ed1bc23
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,51 +72,40 @@ public void lastExecutionGetIdentityNameTest() {
Map<String, String> executionProperties = new HashMap<String, String>();
executionProperties.put(ManagedTask.IDENTITY_NAME, IDENTITY_NAME_TEST_ID);

ScheduledFuture<?> sf = scheduledExecutor.schedule(
scheduledExecutor.schedule(
ManagedExecutors.managedTask(new CounterRunnableTask(), executionProperties, null),
new LogicDrivenTrigger(TestConstants.pollInterval.toMillis(), testname));
Wait.waitTillFutureIsDone(sf);

assertEquals(LogicDrivenTrigger.RIGHT_COUNT, // expected
StaticCounter.getCount(), // actual
"Got wrong identity name. See server log for more details.");

StaticCounter.waitTill(LogicDrivenTrigger.RIGHT_COUNT, "Got wrong identity name. See server log for more details.");
}

@Assertion(id = "JAVADOC:16", strategy = "Result of the last execution.")
public void lastExecutionGetResultRunnableTest() {
// test with runnable, LastExecution should return null
ScheduledFuture<?> sf = scheduledExecutor.schedule(
scheduledExecutor.schedule(
ManagedExecutors.managedTask(new CounterRunnableTask(), null, null),
new LogicDrivenTrigger(TestConstants.pollInterval.toMillis(), testname));
Wait.waitTillFutureIsDone(sf);

assertEquals(LogicDrivenTrigger.RIGHT_COUNT, // expected
StaticCounter.getCount(), // actual
"Got wrong last execution result. See server log for more details.");

StaticCounter.waitTill(LogicDrivenTrigger.RIGHT_COUNT, "Got wrong last execution result. See server log for more details.");
}

@Assertion(id = "JAVADOC:16", strategy = "Result of the last execution.")
public void lastExecutionGetResultCallableTest() {
// test with callable, LastExecution should return 1
ScheduledFuture<?> sf = scheduledExecutor.schedule(
scheduledExecutor.schedule(
ManagedExecutors.managedTask(new CounterCallableTask(), null, null),
new LogicDrivenTrigger(TestConstants.pollInterval.toMillis(), testname));
Wait.waitTillFutureIsDone(sf);

assertEquals(LogicDrivenTrigger.RIGHT_COUNT, // expected
StaticCounter.getCount(), // actual
"Got wrong last execution result. See server log for more details.");

StaticCounter.waitTill(LogicDrivenTrigger.RIGHT_COUNT, "Got wrong last execution result. See server log for more details.");
}

@Assertion(id = "JAVADOC:17 JAVADOC:18 JAVADOC:19", strategy = "The last time in which the task was completed.")
public void lastExecutionGetRunningTimeTest() {
ScheduledFuture<?> sf = scheduledExecutor.schedule(
scheduledExecutor.schedule(
ManagedExecutors.managedTask(new CounterRunnableTask(TestConstants.pollInterval), null, null),
new LogicDrivenTrigger(TestConstants.pollInterval.toMillis(), testname));
Wait.waitTillFutureIsDone(sf);
assertEquals(LogicDrivenTrigger.RIGHT_COUNT, // expected
StaticCounter.getCount(), // actual
"Got wrong last execution result.");

StaticCounter.waitTill(LogicDrivenTrigger.RIGHT_COUNT, "Got wrong last execution result. See server log for more details.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void triggerGetNextRunTimeTest() throws Exception {
Assertions.assertBetween(StaticCounter.getCount(), TestConstants.pollsPerTimeout - 2,
TestConstants.pollsPerTimeout + 2);
} finally {
Wait.waitTillFutureIsDone(result);
Wait.waitForTaskComplete(result);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,15 @@ public static void reset() {
}

public static void waitTill(final int expected) {
waitTill(expected, "Expected count " + expected + " within timeout.");
}

public static void waitTill(final int expected, final String message) {
assertTimeoutPreemptively(TestConstants.waitTimeout, () -> {
for (; expected != StaticCounter.getCount(); Wait.sleep(TestConstants.pollInterval)) {
//empty
}
});
}, message);
}

public static void waitTillSurpassed(final int expected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,6 @@ public static void waitForListenerComplete(final ManagedTaskListenerImpl managed
});
}

/**
* Waits for future to complete, but will timeout after
* {@link TestConstants#waitTimeout}, and will be polled every
* {@link TestConstants#pollInterval}
*
* The difference between this method and waitForTaskComplete is that some
* scheduled task will return values for multiple times, in this situation
* waitForTaskComplete does not work.
*
* @param future - the future to wait for
*/
public static void waitTillFutureIsDone(final Future<?> future) {
assertTimeoutPreemptively(TestConstants.waitTimeout, () -> {
for (; !future.isDone(); sleep(TestConstants.pollInterval)) {
//empty
}
});
}

/**
* Waits for future to throw an error, but will timeout after
* {@link TestConstants#waitTimeout}, and will be polled every
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,13 @@ public void testExecute() {
strategy = "Test basic function for ManagedExecutorService: submit")
public void testSubmit() throws Exception {
Future<?> result = executor.submit(new CommonTasks.SimpleCallable());
Wait.waitTillFutureIsDone(result);
assertEquals(result.get(), TestConstants.simpleReturnValue);
assertEquals(Wait.waitForTaskComplete(result), TestConstants.simpleReturnValue);

result = executor.submit(new CommonTasks.SimpleRunnable());
Wait.waitTillFutureIsDone(result);
result.get();
Wait.waitForTaskComplete(result);

result = executor.submit(new CommonTasks.SimpleRunnable(), TestConstants.simpleReturnValue);
Wait.waitTillFutureIsDone(result);
assertEquals(result.get(), TestConstants.simpleReturnValue);
assertEquals(Wait.waitForTaskComplete(result), TestConstants.simpleReturnValue);
}

@Assertion(id = "SPEC:14.4; SPEC:6.1; SPEC:6.2; SPEC:8",
Expand Down Expand Up @@ -119,15 +116,15 @@ public void testInvokeAll() {
taskList.add(new CommonTasks.SimpleArgCallable(3));
List<Future<Integer>> resultList = executor.invokeAll(taskList);
for (Future<?> each : resultList) {
Wait.waitTillFutureIsDone(each);
Wait.waitForTaskComplete(each);
}
assertEquals(resultList.get(0).get(), 1);
assertEquals(resultList.get(1).get(), 2);
assertEquals(resultList.get(2).get(), 3);

resultList = executor.invokeAll(taskList, TestConstants.waitTimeout.getSeconds(), TimeUnit.SECONDS);
for (Future<?> each : resultList) {
Wait.waitTillFutureIsDone(each);
Wait.waitForTaskComplete(each);
}
assertEquals(resultList.get(0).get(), 1);
assertEquals(resultList.get(1).get(), 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,13 @@ public void before() {
@Assertion(id = "SPEC:44.1", strategy = "Test basic function for ManagedScheduledExecutorService: submit")
public void testApiSubmit() throws Exception {
Future<?> result = scheduledExecutor.submit(new CommonTasks.SimpleCallable());
Wait.waitTillFutureIsDone(result);
assertEquals(result.get(), TestConstants.simpleReturnValue);
assertEquals(Wait.waitForTaskComplete(result), TestConstants.simpleReturnValue);

result = scheduledExecutor.submit(new CommonTasks.SimpleRunnable());
Wait.waitTillFutureIsDone(result);
result.get();
Wait.waitForTaskComplete(result);

result = scheduledExecutor.submit(new CommonTasks.SimpleRunnable(), TestConstants.simpleReturnValue);
Wait.waitTillFutureIsDone(result);
assertEquals(result.get(), TestConstants.simpleReturnValue);
assertEquals(Wait.waitForTaskComplete(result), TestConstants.simpleReturnValue);
}

@Assertion(id = "SPEC:44.2", strategy = "Test basic function for ManagedScheduledExecutorService: execute")
Expand All @@ -98,15 +95,15 @@ public void testApiInvokeAll() throws Exception {
taskList.add(new CommonTasks.SimpleArgCallable(3));
List<Future<Integer>> resultList = scheduledExecutor.invokeAll(taskList);
for (Future<?> each : resultList) {
Wait.waitTillFutureIsDone(each);
Wait.waitForTaskComplete(each);
}
assertEquals(resultList.get(0).get(), 1);
assertEquals(resultList.get(1).get(), 2);
assertEquals(resultList.get(2).get(), 3);
resultList = scheduledExecutor.invokeAll(taskList, TestConstants.waitTimeout.getSeconds(),
TimeUnit.SECONDS);
for (Future<?> each : resultList) {
Wait.waitTillFutureIsDone(each);
Wait.waitForTaskComplete(each);
}
assertEquals(resultList.get(0).get(), 1);
assertEquals(resultList.get(1).get(), 2);
Expand Down Expand Up @@ -154,13 +151,11 @@ public void testApiInvokeAny() throws Exception {
public void testApiSchedule() throws Exception {
Future<?> result = scheduledExecutor.schedule(new CommonTasks.SimpleCallable(),
TestConstants.pollInterval.getSeconds(), TimeUnit.SECONDS);
Wait.waitTillFutureIsDone(result);
assertEquals(result.get(), TestConstants.simpleReturnValue);
assertEquals(Wait.waitForTaskComplete(result), TestConstants.simpleReturnValue);

result = scheduledExecutor.schedule(new CommonTasks.SimpleRunnable(), TestConstants.pollInterval.getSeconds(),
TimeUnit.SECONDS);
Wait.waitTillFutureIsDone(result);
assertEquals(result.get(), null);
assertEquals(Wait.waitForTaskComplete(result), null);
}

@Assertion(id = "SPEC:44.6", strategy = "Test basic function for ManagedScheduledExecutorService: scheduleAtFixedRate")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,13 @@ public class TestEjb implements TestEjbInterface {
public void testApiSubmit() {
try {
Future<?> result = scheduledExecutor.submit(new CommonTasks.SimpleCallable());
Wait.waitTillFutureIsDone(result);
assertEquals(result.get(), TestConstants.simpleReturnValue);
assertEquals(Wait.waitForTaskComplete(result), TestConstants.simpleReturnValue);

result = scheduledExecutor.submit(new CommonTasks.SimpleRunnable());
Wait.waitTillFutureIsDone(result);
result.get();
Wait.waitForTaskComplete(result);

result = scheduledExecutor.submit(new CommonTasks.SimpleRunnable(), TestConstants.simpleReturnValue);
Wait.waitTillFutureIsDone(result);
assertEquals(result.get(), TestConstants.simpleReturnValue);
assertEquals(Wait.waitForTaskComplete(result), TestConstants.simpleReturnValue);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand All @@ -87,7 +84,7 @@ public void testApiInvokeAll() {
taskList.add(new CommonTasks.SimpleArgCallable(3));
List<Future<Integer>> resultList = scheduledExecutor.invokeAll(taskList);
for (Future<?> each : resultList) {
Wait.waitTillFutureIsDone(each);
Wait.waitForTaskComplete(each);
}
assertEquals(resultList.get(0).get(), 1);
assertEquals(resultList.get(1).get(), 2);
Expand All @@ -96,7 +93,7 @@ public void testApiInvokeAll() {
resultList = scheduledExecutor.invokeAll(taskList, TestConstants.waitTimeout.getSeconds(),
TimeUnit.SECONDS);
for (Future<?> each : resultList) {
Wait.waitTillFutureIsDone(each);
Wait.waitForTaskComplete(each);
}
assertEquals(resultList.get(0).get(), 1);
assertEquals(resultList.get(1).get(), 2);
Expand Down Expand Up @@ -151,13 +148,11 @@ public void testApiSchedule() {
try {
Future<?> result = scheduledExecutor.schedule(new CommonTasks.SimpleCallable(),
TestConstants.pollInterval.getSeconds(), TimeUnit.SECONDS);
Wait.waitTillFutureIsDone(result);
assertEquals(TestConstants.simpleReturnValue, result.get());
assertEquals(TestConstants.simpleReturnValue, Wait.waitForTaskComplete(result));

result = scheduledExecutor.schedule(new CommonTasks.SimpleRunnable(),
TestConstants.pollInterval.getSeconds(), TimeUnit.SECONDS);
Wait.waitTillFutureIsDone(result);
assertEquals(result.get(), null);
assertEquals(null, Wait.waitForTaskComplete(result));
} catch (Exception e) {
fail(e.getMessage());
}
Expand Down

0 comments on commit ed1bc23

Please sign in to comment.