add tests for runRead, etc.

Signed-off-by: mmews <marcus.mews@numberfour.eu>
This commit is contained in:
mmews 2019-12-11 14:16:53 +01:00
parent 3102556c4e
commit df3b967105
2 changed files with 111 additions and 6 deletions

View file

@ -47,7 +47,23 @@ class RequestManagerTest {
}
@Test(timeout = 1000)
def void testLogException() {
def void testRunWriteLogExceptionNonCancellable() {
val logResult = LoggingTester.captureLogging(Level.ALL, RequestManager, [
val future = requestManager.runWrite([], [
throw new RuntimeException();
])
// join future to assert log later
try {
future.join
} catch (Exception e) {}
])
logResult.assertLogEntry("Error during request:")
}
@Test(timeout = 1000)
def void testRunWriteLogExceptionCancellable() {
val logResult = LoggingTester.captureLogging(Level.ALL, RequestManager, [
val future = requestManager.runWrite([
throw new RuntimeException();
@ -55,7 +71,7 @@ class RequestManagerTest {
// join future to assert log later
try {
future.get
future.join
} catch (Exception e) {}
])
@ -63,7 +79,7 @@ class RequestManagerTest {
}
@Test(timeout = 1000, expected = ExecutionException)
def void testCatchException() {
def void testRunWriteCatchException() {
LoggingTester.captureLogging(Level.ALL, RequestManager, [
val future = requestManager.runWrite([
throw new RuntimeException()
@ -75,6 +91,35 @@ class RequestManagerTest {
Assert.fail
}
@Test(timeout = 1000)
def void testRunReadLogException() {
val logResult = LoggingTester.captureLogging(Level.ALL, RequestManager, [
val future = requestManager.runRead([
throw new RuntimeException();
])
// join future to assert log later
try {
future.join
} catch (Exception e) {}
])
logResult.assertLogEntry("Error during request:")
}
@Test(timeout = 1000, expected = ExecutionException)
def void testRunReadCatchException() {
LoggingTester.captureLogging(Level.ALL, RequestManager, [
val future = requestManager.runRead([
throw new RuntimeException()
])
assertEquals('Foo', future.get)
])
Assert.fail
}
@Test(timeout = 1000)
def void testRunRead() {
val future = requestManager.runRead [

View file

@ -53,7 +53,30 @@ public class RequestManagerTest {
}
@Test(timeout = 1000)
public void testLogException() {
public void testRunWriteLogExceptionNonCancellable() {
final Runnable _function = () -> {
final Function0<Object> _function_1 = () -> {
return null;
};
final Function2<CancelIndicator, Object, Object> _function_2 = (CancelIndicator $0, Object $1) -> {
throw new RuntimeException();
};
final CompletableFuture<Object> future = this.requestManager.<Object, Object>runWrite(_function_1, _function_2);
try {
future.join();
} catch (final Throwable _t) {
if (_t instanceof Exception) {
} else {
throw Exceptions.sneakyThrow(_t);
}
}
};
final LoggingTester.LogCapture logResult = LoggingTester.captureLogging(Level.ALL, RequestManager.class, _function);
logResult.assertLogEntry("Error during request:");
}
@Test(timeout = 1000)
public void testRunWriteLogExceptionCancellable() {
final Runnable _function = () -> {
final Function0<Object> _function_1 = () -> {
throw new RuntimeException();
@ -63,7 +86,7 @@ public class RequestManagerTest {
};
final CompletableFuture<Object> future = this.requestManager.<Object, Object>runWrite(_function_1, _function_2);
try {
future.get();
future.join();
} catch (final Throwable _t) {
if (_t instanceof Exception) {
} else {
@ -76,7 +99,7 @@ public class RequestManagerTest {
}
@Test(timeout = 1000, expected = ExecutionException.class)
public void testCatchException() {
public void testRunWriteCatchException() {
final Runnable _function = () -> {
try {
final Function0<Object> _function_1 = () -> {
@ -95,6 +118,43 @@ public class RequestManagerTest {
Assert.fail();
}
@Test(timeout = 1000)
public void testRunReadLogException() {
final Runnable _function = () -> {
final Function1<CancelIndicator, Object> _function_1 = (CancelIndicator it) -> {
throw new RuntimeException();
};
final CompletableFuture<Object> future = this.requestManager.<Object>runRead(_function_1);
try {
future.join();
} catch (final Throwable _t) {
if (_t instanceof Exception) {
} else {
throw Exceptions.sneakyThrow(_t);
}
}
};
final LoggingTester.LogCapture logResult = LoggingTester.captureLogging(Level.ALL, RequestManager.class, _function);
logResult.assertLogEntry("Error during request:");
}
@Test(timeout = 1000, expected = ExecutionException.class)
public void testRunReadCatchException() {
final Runnable _function = () -> {
try {
final Function1<CancelIndicator, Object> _function_1 = (CancelIndicator it) -> {
throw new RuntimeException();
};
final CompletableFuture<Object> future = this.requestManager.<Object>runRead(_function_1);
Assert.assertEquals("Foo", future.get());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
};
LoggingTester.captureLogging(Level.ALL, RequestManager.class, _function);
Assert.fail();
}
@Test(timeout = 1000)
public void testRunRead() {
try {