Search in sources :

Example 1 with InvalidateL1Command

use of org.infinispan.commands.write.InvalidateL1Command in project infinispan by infinispan.

the class DistAsyncFuncTest method createCacheManagers.

@Override
protected void createCacheManagers() throws Throwable {
    super.createCacheManagers();
    r1 = new ReplListener(c1, true, true);
    r2 = new ReplListener(c2, true, true);
    r3 = new ReplListener(c3, true, true);
    r4 = new ReplListener(c4, true, true);
    r = new ReplListener[] { r1, r2, r3, r4 };
    listenerLookup = new HashMap<>();
    for (ReplListener rl : r) listenerLookup.put(rl.getCache().getCacheManager().getAddress(), rl);
    for (Cache c : caches) {
        TestingUtil.wrapComponent(c, RpcManager.class, original -> new AbstractDelegatingRpcManager(original) {

            @Override
            protected <T> CompletionStage<T> performRequest(Collection<Address> targets, ReplicableCommand command, ResponseCollector<T> collector, Function<ResponseCollector<T>, CompletionStage<T>> invoker, RpcOptions rpcOptions) {
                if (command instanceof SingleRpcCommand) {
                    command = ((SingleRpcCommand) command).getCommand();
                }
                if (command instanceof InvalidateL1Command) {
                    InvalidateL1Command invalidateL1Command = (InvalidateL1Command) command;
                    log.tracef("Sending invalidation %s to %s", command, targets);
                    Collection<Address> realTargets = targets != null ? targets : cacheAddresses;
                    for (Address target : realTargets) {
                        expectedL1Invalidations.computeIfAbsent(target, ignored -> Collections.synchronizedList(new ArrayList<>())).add(invalidateL1Command);
                    }
                }
                return super.performRequest(targets, command, collector, invoker, rpcOptions);
            }
        });
    }
}
Also used : Address(org.infinispan.remoting.transport.Address) ReplicableCommand(org.infinispan.commands.ReplicableCommand) ArrayList(java.util.ArrayList) InvalidateL1Command(org.infinispan.commands.write.InvalidateL1Command) SingleRpcCommand(org.infinispan.commands.remote.SingleRpcCommand) AbstractDelegatingRpcManager(org.infinispan.util.AbstractDelegatingRpcManager) ResponseCollector(org.infinispan.remoting.transport.ResponseCollector) RpcOptions(org.infinispan.remoting.rpc.RpcOptions) Collection(java.util.Collection) ReplListener(org.infinispan.test.ReplListener) CompletionStage(java.util.concurrent.CompletionStage) Cache(org.infinispan.Cache)

Example 2 with InvalidateL1Command

use of org.infinispan.commands.write.InvalidateL1Command in project infinispan by infinispan.

the class DistAsyncFuncTest method waitForInvalidations.

private void waitForInvalidations() {
    for (Map.Entry<Address, List<InvalidateL1Command>> expected : expectedL1Invalidations.entrySet()) {
        Address address = expected.getKey();
        ReplListener replListener = listenerLookup.get(address);
        List<InvalidateL1Command> list = expected.getValue();
        if (!list.isEmpty()) {
            log.tracef("Waiting for invalidations on %s: %s", address, list);
            synchronized (list) {
                for (InvalidateL1Command cmd : list) {
                    replListener.expect(InvalidateL1Command.class);
                }
                list.clear();
            }
            replListener.waitForRpc();
        }
    }
}
Also used : Address(org.infinispan.remoting.transport.Address) ArrayList(java.util.ArrayList) List(java.util.List) ReplListener(org.infinispan.test.ReplListener) InvalidateL1Command(org.infinispan.commands.write.InvalidateL1Command) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 3 with InvalidateL1Command

use of org.infinispan.commands.write.InvalidateL1Command in project infinispan by infinispan.

the class VersionAwareMarshallerTest method testReplicableCommandsMarshalling.

public void testReplicableCommandsMarshalling() throws Exception {
    ByteString cacheName = ByteString.fromString(TestingUtil.getDefaultCacheName(cm));
    ClusteredGetCommand c2 = new ClusteredGetCommand("key", cacheName, 0, EnumUtil.EMPTY_BIT_SET);
    marshallAndAssertEquality(c2);
    // SizeCommand does not have an empty constructor, so doesn't look to be one that is marshallable.
    GetKeyValueCommand c4 = new GetKeyValueCommand("key", 0, EnumUtil.EMPTY_BIT_SET);
    marshallAndAssertEquality(c4);
    PutKeyValueCommand c5 = new PutKeyValueCommand("k", "v", false, new EmbeddedMetadata.Builder().build(), 0, EnumUtil.EMPTY_BIT_SET, CommandInvocationId.generateId(null));
    marshallAndAssertEquality(c5);
    RemoveCommand c6 = new RemoveCommand("key", null, 0, EnumUtil.EMPTY_BIT_SET, CommandInvocationId.generateId(null));
    marshallAndAssertEquality(c6);
    // EvictCommand does not have an empty constructor, so doesn't look to be one that is marshallable.
    InvalidateCommand c7 = new InvalidateCommand(EnumUtil.EMPTY_BIT_SET, CommandInvocationId.generateId(null), "key1", "key2");
    marshallAndAssertEquality(c7);
    InvalidateCommand c71 = new InvalidateL1Command(EnumUtil.EMPTY_BIT_SET, CommandInvocationId.generateId(null), "key1", "key2");
    marshallAndAssertEquality(c71);
    ReplaceCommand c8 = new ReplaceCommand("key", "oldvalue", "newvalue", new EmbeddedMetadata.Builder().build(), 0, EnumUtil.EMPTY_BIT_SET, CommandInvocationId.generateId(null));
    marshallAndAssertEquality(c8);
    ClearCommand c9 = new ClearCommand();
    marshallAndAssertEquality(c9);
    Map<Integer, GlobalTransaction> m1 = new HashMap<>();
    for (int i = 0; i < 10; i++) {
        GlobalTransaction gtx = gtf.newGlobalTransaction(new JGroupsAddress(UUID.randomUUID()), false);
        m1.put(1000 * i, gtx);
    }
    PutMapCommand c10 = new PutMapCommand(m1, new EmbeddedMetadata.Builder().build(), EnumUtil.EMPTY_BIT_SET, CommandInvocationId.generateId(null));
    marshallAndAssertEquality(c10);
    Address local = new JGroupsAddress(UUID.randomUUID());
    GlobalTransaction gtx = gtf.newGlobalTransaction(local, false);
    PrepareCommand c11 = new PrepareCommand(cacheName, gtx, true, c5, c6, c8, c10);
    marshallAndAssertEquality(c11);
    CommitCommand c12 = new CommitCommand(cacheName, gtx);
    marshallAndAssertEquality(c12);
    RollbackCommand c13 = new RollbackCommand(cacheName, gtx);
    marshallAndAssertEquality(c13);
}
Also used : RemoveCommand(org.infinispan.commands.write.RemoveCommand) IpAddress(org.jgroups.stack.IpAddress) JGroupsAddress(org.infinispan.remoting.transport.jgroups.JGroupsAddress) Address(org.infinispan.remoting.transport.Address) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) FastCopyHashMap(org.infinispan.commons.util.FastCopyHashMap) HashMap(java.util.HashMap) ByteString(org.infinispan.util.ByteString) JGroupsAddress(org.infinispan.remoting.transport.jgroups.JGroupsAddress) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) AutoProtoSchemaBuilder(org.infinispan.protostream.annotations.AutoProtoSchemaBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction) PrepareCommand(org.infinispan.commands.tx.PrepareCommand) InvalidateL1Command(org.infinispan.commands.write.InvalidateL1Command) ClusteredGetCommand(org.infinispan.commands.remote.ClusteredGetCommand) PutMapCommand(org.infinispan.commands.write.PutMapCommand) GetKeyValueCommand(org.infinispan.commands.read.GetKeyValueCommand) ReplaceCommand(org.infinispan.commands.write.ReplaceCommand) RollbackCommand(org.infinispan.commands.tx.RollbackCommand) ClearCommand(org.infinispan.commands.write.ClearCommand) CommitCommand(org.infinispan.commands.tx.CommitCommand) InvalidateCommand(org.infinispan.commands.write.InvalidateCommand) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand)

Aggregations

InvalidateL1Command (org.infinispan.commands.write.InvalidateL1Command)3 Address (org.infinispan.remoting.transport.Address)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ReplListener (org.infinispan.test.ReplListener)2 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 CompletionStage (java.util.concurrent.CompletionStage)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Cache (org.infinispan.Cache)1 ReplicableCommand (org.infinispan.commands.ReplicableCommand)1 GetKeyValueCommand (org.infinispan.commands.read.GetKeyValueCommand)1 ClusteredGetCommand (org.infinispan.commands.remote.ClusteredGetCommand)1 SingleRpcCommand (org.infinispan.commands.remote.SingleRpcCommand)1 CommitCommand (org.infinispan.commands.tx.CommitCommand)1 PrepareCommand (org.infinispan.commands.tx.PrepareCommand)1 RollbackCommand (org.infinispan.commands.tx.RollbackCommand)1 ClearCommand (org.infinispan.commands.write.ClearCommand)1