Search in sources :

Example 1 with EntryFactory

use of org.infinispan.container.impl.EntryFactory in project infinispan by infinispan.

the class ConditionalOperationPrimaryOwnerFailTest method testEntryNotWrapped.

public void testEntryNotWrapped() throws Throwable {
    assertClusterSize("Wrong cluster size!", 3);
    final Object key = new MagicKey(cache(0), cache(1));
    final Cache<Object, Object> futureBackupOwnerCache = cache(2);
    cache(0).put(key, INITIAL_VALUE);
    final PerCacheInboundInvocationHandler spyHandler = spyInvocationHandler(futureBackupOwnerCache);
    final EntryFactory spyEntryFactory = spyEntryFactory(futureBackupOwnerCache);
    // it blocks the StateResponseCommand.class
    final CountDownLatch latch1 = new CountDownLatch(1);
    final CountDownLatch latch2 = new CountDownLatch(1);
    doAnswer(invocation -> {
        CacheRpcCommand command = (CacheRpcCommand) invocation.getArguments()[0];
        if (command instanceof StateResponseCommand) {
            log.debugf("Blocking command %s", command);
            latch2.countDown();
            latch1.await();
        }
        return invocation.callRealMethod();
    }).when(spyHandler).handle(any(CacheRpcCommand.class), any(Reply.class), any(DeliverOrder.class));
    doAnswer(invocation -> {
        InvocationContext context = (InvocationContext) invocation.getArguments()[0];
        log.debugf("wrapEntryForWriting invoked with %s", context);
        CompletionStage<Void> stage = (CompletionStage<Void>) invocation.callRealMethod();
        CompletionStages.join(stage);
        assertNull(context.lookupEntry(key), "Entry should not be wrapped!");
        return stage;
    }).when(spyEntryFactory).wrapEntryForWriting(any(InvocationContext.class), any(), anyInt(), anyBoolean(), anyBoolean(), any());
    Future<?> killMemberResult = fork(() -> killMember(1));
    // await until the key is received from state transfer (the command is blocked now...)
    latch2.await(30, TimeUnit.SECONDS);
    futureBackupOwnerCache.put(key, FINAL_VALUE);
    latch1.countDown();
    killMemberResult.get(30, TimeUnit.SECONDS);
}
Also used : EntryFactory(org.infinispan.container.impl.EntryFactory) PerCacheInboundInvocationHandler(org.infinispan.remoting.inboundhandler.PerCacheInboundInvocationHandler) DeliverOrder(org.infinispan.remoting.inboundhandler.DeliverOrder) CountDownLatch(java.util.concurrent.CountDownLatch) CacheRpcCommand(org.infinispan.commands.remote.CacheRpcCommand) StateResponseCommand(org.infinispan.commands.statetransfer.StateResponseCommand) Reply(org.infinispan.remoting.inboundhandler.Reply) InvocationContext(org.infinispan.context.InvocationContext) MagicKey(org.infinispan.distribution.MagicKey) CompletionStage(java.util.concurrent.CompletionStage)

Example 2 with EntryFactory

use of org.infinispan.container.impl.EntryFactory in project infinispan by infinispan.

the class ConditionalOperationPrimaryOwnerFailTest method spyEntryFactory.

private EntryFactory spyEntryFactory(Cache<Object, Object> cache) {
    EntryFactory spy = spy(extractComponent(cache, EntryFactory.class));
    TestingUtil.replaceComponent(cache, EntryFactory.class, spy, true);
    return spy;
}
Also used : EntryFactory(org.infinispan.container.impl.EntryFactory)

Aggregations

EntryFactory (org.infinispan.container.impl.EntryFactory)2 CompletionStage (java.util.concurrent.CompletionStage)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 CacheRpcCommand (org.infinispan.commands.remote.CacheRpcCommand)1 StateResponseCommand (org.infinispan.commands.statetransfer.StateResponseCommand)1 InvocationContext (org.infinispan.context.InvocationContext)1 MagicKey (org.infinispan.distribution.MagicKey)1 DeliverOrder (org.infinispan.remoting.inboundhandler.DeliverOrder)1 PerCacheInboundInvocationHandler (org.infinispan.remoting.inboundhandler.PerCacheInboundInvocationHandler)1 Reply (org.infinispan.remoting.inboundhandler.Reply)1