protected void invoke(Object session, InvocationContext ctx, RemoveCommand command) { invoker.invoke(ctx, command); }
protected AsyncInterceptorChain mockEntrySet(final Cache<?, ?> cache, StreamMocking mocking) { AsyncInterceptorChain chain = TestingUtil.extractComponent(cache, AsyncInterceptorChain.class); AsyncInterceptorChain mockChain = spy(chain); doAnswer(i -> { CacheSet cacheSet = (CacheSet) i.callRealMethod(); CacheSet mockSet = mock(CacheSet.class, withSettings().defaultAnswer(delegatesTo(cacheSet))); when(mockSet.stream()).then(j -> { CacheStream stream = cacheSet.stream(); return mockStream(stream, mocking); }); return mockSet; }).when(mockChain).invoke(any(InvocationContext.class), any(EntrySetCommand.class)); TestingUtil.replaceComponent(cache, AsyncInterceptorChain.class, mockChain, true); return chain; } }
public void testComposeSync() { AsyncInterceptorChain chain = newInterceptorChain(new BaseAsyncInterceptor() { @Override public Object visitCommand(InvocationContext ctx, VisitableCommand command) throws Throwable { return invokeNextAndHandle(ctx, command, (rCtx, rCommand, rv, t) -> "v1"); } }, new BaseAsyncInterceptor() { @Override public Object visitCommand(InvocationContext ctx, VisitableCommand command) throws Throwable { return "v2"; } }); InvocationContext context = newInvocationContext(); Object returnValue = chain.invoke(context, testCommand); assertEquals("v1", returnValue); }
public void testInvokeNextSubCommand() { AsyncInterceptorChain chain = newInterceptorChain(new BaseAsyncInterceptor() { @Override public Object visitCommand(InvocationContext ctx, VisitableCommand command) throws Throwable { return invokeNext(ctx, testSubCommand); } }, new BaseAsyncInterceptor() { @Override public Object visitCommand(InvocationContext ctx, VisitableCommand command) throws Throwable { return command instanceof LockControlCommand ? "subCommand" : "command"; } }); InvocationContext context = newInvocationContext(); Object returnValue = chain.invoke(context, testCommand); assertEquals("subCommand", returnValue); }
public void testCompletedStage() { AsyncInterceptorChain chain = newInterceptorChain(new BaseAsyncInterceptor() { @Override public Object visitCommand(InvocationContext ctx, VisitableCommand command) throws Throwable { return "v1"; } }, new BaseAsyncInterceptor() { @Override public Object visitCommand(InvocationContext ctx, VisitableCommand command) throws Throwable { return "v2"; } }); InvocationContext context = newInvocationContext(); Object returnValue = chain.invoke(context, testCommand); assertEquals("v1", returnValue); }
public static void replicateCommand(Cache cache, VisitableCommand command) throws Throwable { ComponentRegistry cr = extractComponentRegistry(cache); AsyncInterceptorChain ic = cr.getComponent(AsyncInterceptorChain.class); InvocationContextFactory icf = cr.getComponent(InvocationContextFactory.class); InvocationContext ctxt = icf.createInvocationContext(true, -1); ic.invoke(ctxt, command); }