@SuppressWarnings("ConstantConditions") public void testReplaceNullParameters() { expectException(NullPointerException.class, "Null keys are not supported!", () -> cache.replace(null, null)); expectException(NullPointerException.class, "Null keys are not supported!", () -> cache.replace(null, "X")); expectException(NullPointerException.class, "Null keys are not supported!", () -> cache.replace(null, "X", "Y")); expectException(NullPointerException.class, "Null values are not supported!", () -> cache.replace("hello", null, "X")); expectException(NullPointerException.class, "Null values are not supported!", () -> cache.replace("hello", "X", null)); }
public static void expectException(Class<? extends Throwable> exceptionClass, String messageRegex, ExceptionRunnable runnable) { Throwable t = extractException(runnable); assertException(exceptionClass, messageRegex, t); }
@Test(dataProvider = "owningModeAndReadWrites") public void testWriteOnMissingValue(boolean isOwner, WriteMethod method) { Object key = getKey(isOwner, DIST); try { method.eval(key, null, rw, view -> view.get(), (view, nil) -> {}, getClass()); fail("Should throw CompletionException:CacheException:[RemoteException:]*NoSuchElementException"); } catch (CompletionException e) { // catches RemoteExceptions, too Throwable t = e; assertException(CompletionException.class, t); t = t.getCause(); assertExceptionNonStrict(CacheException.class, t); while (t.getCause() instanceof RemoteException && t != t.getCause()) { t = t.getCause(); } assertException(NoSuchElementException.class, t.getCause()); } }
public static void expectExceptionNonStrict(Class<? extends Throwable> e, ExceptionRunnable runnable) { Throwable t = extractException(runnable); assertExceptionNonStrict(e, t); }
@Test public void testGetOccursAfterReplaceRunningBeforeWithRemoteException() throws Exception { final Cache<Object, String> nonOwnerCache = getFirstNonOwner(key); final Cache<Object, String> ownerCache = getFirstOwner(key); ownerCache.put(key, firstValue); CyclicBarrier barrier = new CyclicBarrier(2); addBlockingInterceptorBeforeTx(nonOwnerCache, barrier, ReplaceCommand.class, false); ControlledRpcManager controlledRpcManager = ControlledRpcManager.replaceRpcManager(nonOwnerCache); try { // The replace will internally block the get until it gets the remote value Future<Boolean> futureReplace = fork(() -> nonOwnerCache.replace(key, firstValue, secondValue)); barrier.await(5, TimeUnit.SECONDS); Future<String> futureGet = fork(() -> nonOwnerCache.get(key)); // The get will blocks locally on the L1WriteSynchronizer registered by the replace command Exceptions.expectException(TimeoutException.class, () -> futureGet.get(100, TimeUnit.MILLISECONDS)); controlledRpcManager.expectNoCommand(); // Continue the replace barrier.await(5, TimeUnit.SECONDS); // That also unblocks the get command and allows it to perform the remote get controlledRpcManager.expectCommand(ClusteredGetCommand.class) .skipSend() .receive(address(ownerCache), new ExceptionResponse(new TestException())); Exceptions.expectExecutionException(RemoteException.class, TestException.class, futureReplace); Exceptions.expectExecutionException(RemoteException.class, TestException.class, futureGet); } finally { removeAllBlockingInterceptorsFromCache(nonOwnerCache); controlledRpcManager.revertRpcManager(); } }
public static void assertException(Class<? extends Throwable> wrapperExceptionClass, Class<? extends Throwable> exceptionClass, Throwable t) { assertException(wrapperExceptionClass, t); assertException(exceptionClass, t.getCause()); }
public static void expectExecutionException(Class<? extends Throwable> exceptionClass, String messageRegex, Future<?> future) { expectExecutionException(exceptionClass, messageRegex, future, 10, TimeUnit.SECONDS); }
private <K> void testReadOnMissingValues(K[] keys, FunctionalMap.ReadOnlyMap<K, String> ro, ReadMethod method) throws Exception { tm.begin(); for (K key : keys) { Assert.assertEquals(ro.eval(key, view -> view.find().isPresent()).join(), Boolean.FALSE); } tm.commit(); tm.begin(); for (K key : keys) { expectExceptionNonStrict(CompletionException.class, CacheException.class, NoSuchElementException.class, () -> method.eval(key, ro, EntryView.ReadEntryView::get)); // The first exception should cause the whole transaction to fail assertEquals(Status.STATUS_MARKED_ROLLBACK, tm.getStatus()); tm.rollback(); break; } if (tm.getStatus() == Status.STATUS_ACTIVE) { tm.commit(); } }
public void testInvokeCommand1() throws Exception { ClusteredGetCommand command = TestingUtil.extractCommandsFactory(cache(0)).buildClusteredGetCommand("key", 0, 0L); RpcManager rpcManager0 = cache(0).getAdvancedCache().getRpcManager(); Exceptions.expectException(IllegalArgumentException.class, () -> rpcManager0.invokeCommand(address(0), command, SingleResponseCollector.validOnly(), rpcManager0.getSyncRpcOptions())); command.setTopologyId(rpcManager0.getTopologyId()); CompletionStage<ValidResponse> stage1 = rpcManager0.invokeCommand(address(0), command, SingleResponseCollector.validOnly(), rpcManager0.getSyncRpcOptions()); assertResponse(null, stage1); CompletionStage<ValidResponse> stage2 = rpcManager0.invokeCommand(address(1), command, SingleResponseCollector.validOnly(), rpcManager0.getSyncRpcOptions()); assertResponse(SUCCESSFUL_EMPTY_RESPONSE, stage2); CompletionStage<ValidResponse> stage3 = rpcManager0.invokeCommand(SUSPECT, command, SingleResponseCollector.validOnly(), rpcManager0.getSyncRpcOptions()); Exceptions.expectExecutionException(SuspectException.class, stage3.toCompletableFuture()); }
public static void assertException(Class<? extends Throwable> wrapperExceptionClass, Class<? extends Throwable> exceptionClass, String messageRegex, Throwable t) { assertException(wrapperExceptionClass, t); assertException(exceptionClass, messageRegex, t.getCause()); }
private void assertExceptionHandlers(CompletableFuture<Object> invokeFuture) { String expectedMessage = "|whenComplete|handle|exceptionally"; expectExecutionException(TestException.class, Pattern.quote(expectedMessage), invokeFuture); assertEquals("|whenComplete|handle|exceptionally", sideEffects.get()); }
public static void expectExceptionNonStrict(Class<? extends Throwable> we1, Class<? extends Throwable> e, ExceptionRunnable runnable) { Throwable t = extractException(runnable); assertExceptionNonStrict(we1, t); assertExceptionNonStrict(e, t.getCause()); }
protected <K> void testReadOnMissingValue(K key, FunctionalMap.ReadOnlyMap<K, String> ro, ReadMethod method) { assertEquals(ro.eval(key, view -> view.find().isPresent()).join(), Boolean.FALSE); expectExceptionNonStrict(CompletionException.class, CacheException.class, NoSuchElementException.class, () -> method.eval(key, ro, view -> view.get()) ); }
@SuppressWarnings("ConstantConditions") public void testRemoveNullParameters() { expectException(NullPointerException.class, "Null keys are not supported!", () -> cache.remove(null)); expectException(NullPointerException.class, "Null keys are not supported!", () -> cache.remove(null, "X")); expectException(NullPointerException.class, "Null values are not supported!", () -> cache.remove("k", null)); expectException(NullPointerException.class, "Null keys are not supported!", () -> cache.remove(null, null)); }
public static void expectException(Class<? extends Throwable> wrapperExceptionClass2, Class<? extends Throwable> wrapperExceptionClass1, Class<? extends Throwable> exceptionClass, ExceptionRunnable runnable) { Throwable t = extractException(runnable); assertException(wrapperExceptionClass2, wrapperExceptionClass1, exceptionClass, t); }
public static void assertException(Class<? extends Throwable> wrapperExceptionClass2, Class<? extends Throwable> wrapperExceptionClass, Class<? extends Throwable> exceptionClass, Throwable t) { assertException(wrapperExceptionClass2, t); assertException(wrapperExceptionClass, t.getCause()); assertException(exceptionClass, t.getCause().getCause()); }
@Test(dataProvider = "owningModeAndWriteMethod") public void testExceptionPropagation(boolean isOwner, WriteMethod method) { Object key = getKey(isOwner, SCATTERED); try { method.eval(key, swo, srw, view -> null, (view, nil) -> { throw new TestException(); }, getClass()); fail("Should throw CompletionException:CacheException:[RemoteException:]*TestException"); } catch (CacheException | CompletionException e) { // catches RemoteExceptions, too Throwable t = e; assertException(CompletionException.class, t); t = t.getCause(); assertExceptionNonStrict(CacheException.class, t); while (t.getCause() instanceof RemoteException && t != t.getCause()) { t = t.getCause(); } assertException(TestException.class, t.getCause()); } }
@Override public void call() throws InterruptedException, ExecutionException, TimeoutException { EmbeddedCacheManager cm1 = cms[0]; CompletableFuture<Void> future = executor(cm1).submitConsumer(m -> null, (a, i, t) -> { throw new NullPointerException(); }); Exceptions.expectExecutionException(NullPointerException.class, future); } });
public static void expectExceptionNonStrict(Class<? extends Throwable> we2, Class<? extends Throwable> we1, Class<? extends Throwable> e, ExceptionRunnable runnable) { Throwable t = extractException(runnable); assertExceptionNonStrict(we2, t); assertExceptionNonStrict(we1, t.getCause()); assertExceptionNonStrict(e, t.getCause().getCause()); }
@SuppressWarnings("ConstantConditions") public void testPutNullParameters() { expectException(NullPointerException.class, "Null keys are not supported!", () -> cache.put(null, null)); expectException(NullPointerException.class, "Null values are not supported!", () -> cache.put("k", null)); expectException(NullPointerException.class, "Null keys are not supported!", () -> cache.put(null, "v")); //put if absent since it shares the same command as put expectException(NullPointerException.class, "Null keys are not supported!", () -> cache.putIfAbsent(null, null)); expectException(NullPointerException.class, "Null values are not supported!", () -> cache.putIfAbsent("k", null)); expectException(NullPointerException.class, "Null keys are not supported!", () -> cache.putIfAbsent(null, "v")); }