Search in sources :

Example 1 with ReplaceCommand

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

the class CacheMgmtInterceptorTest method testVisitReplaceCommandException.

public void testVisitReplaceCommandException() throws Throwable {
    ReplaceCommand command = new ReplaceCommand(KEY, VALUE, false, null, 0, 0, null);
    InvocationStage stage = makeStage(interceptor.visitReplaceCommand(ctx, command));
    assertFalse(stage.isDone());
    timeService.advance(1);
    nextInterceptor.completeLastInvocationExceptionally(new TestException());
    expectInvocationException(stage);
    assertEquals(1, interceptor.getAverageWriteTime());
}
Also used : InvocationStage(org.infinispan.interceptors.InvocationStage) TestException(org.infinispan.test.TestException) ReplaceCommand(org.infinispan.commands.write.ReplaceCommand)

Example 2 with ReplaceCommand

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

the class CacheMgmtInterceptorTest method testVisitReplaceCommand.

public void testVisitReplaceCommand() throws Throwable {
    ReplaceCommand command = new ReplaceCommand(KEY, VALUE, false, null, 0, 0, null);
    InvocationStage stage = makeStage(interceptor.visitReplaceCommand(ctx, command));
    assertFalse(stage.isDone());
    timeService.advance(1);
    nextInterceptor.completeLastInvocation(null);
    assertNull(stage.get());
    assertEquals(1, interceptor.getAverageWriteTime());
}
Also used : InvocationStage(org.infinispan.interceptors.InvocationStage) ReplaceCommand(org.infinispan.commands.write.ReplaceCommand)

Example 3 with ReplaceCommand

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

the class SingleKeyBackupWriteCommand method createWriteCommand.

@Override
WriteCommand createWriteCommand() {
    DataWriteCommand command;
    switch(operation) {
        case REMOVE:
            command = new RemoveCommand(key, null, segmentId, getFlags(), getCommandInvocationId());
            break;
        case WRITE:
            command = EnumUtil.containsAny(getFlags(), FlagBitSets.IRAC_UPDATE) ? new IracPutKeyValueCommand(key, segmentId, getCommandInvocationId(), valueOrFunction, metadata, internalMetadata) : new PutKeyValueCommand(key, valueOrFunction, false, metadata, segmentId, getFlags(), getCommandInvocationId());
            break;
        case COMPUTE:
            command = new ComputeCommand(key, (BiFunction) valueOrFunction, false, segmentId, getFlags(), getCommandInvocationId(), metadata);
            break;
        case REPLACE:
            command = new ReplaceCommand(key, null, valueOrFunction, metadata, segmentId, getFlags(), getCommandInvocationId());
            break;
        case REMOVE_EXPIRED:
            // Doesn't matter if it is max idle or not - important thing is that it raises expired event
            command = new RemoveExpiredCommand(key, valueOrFunction, null, false, segmentId, getFlags(), getCommandInvocationId());
            break;
        case COMPUTE_IF_PRESENT:
            command = new ComputeCommand(key, (BiFunction) valueOrFunction, true, segmentId, getFlags(), getCommandInvocationId(), metadata);
            break;
        case COMPUTE_IF_ABSENT:
            command = new ComputeIfAbsentCommand(key, (Function) valueOrFunction, segmentId, getFlags(), getCommandInvocationId(), metadata);
            break;
        default:
            throw new IllegalStateException("Unknown operation " + operation);
    }
    command.setInternalMetadata(internalMetadata);
    return command;
}
Also used : RemoveCommand(org.infinispan.commands.write.RemoveCommand) ComputeCommand(org.infinispan.commands.write.ComputeCommand) BiFunction(java.util.function.BiFunction) Function(java.util.function.Function) DataWriteCommand(org.infinispan.commands.write.DataWriteCommand) BiFunction(java.util.function.BiFunction) ReplaceCommand(org.infinispan.commands.write.ReplaceCommand) RemoveExpiredCommand(org.infinispan.commands.write.RemoveExpiredCommand) ComputeIfAbsentCommand(org.infinispan.commands.write.ComputeIfAbsentCommand) IracPutKeyValueCommand(org.infinispan.commands.write.IracPutKeyValueCommand) IracPutKeyValueCommand(org.infinispan.commands.write.IracPutKeyValueCommand) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand)

Example 4 with ReplaceCommand

use of org.infinispan.commands.write.ReplaceCommand 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)

Example 5 with ReplaceCommand

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

the class CacheImpl method replaceAsync.

final CompletableFuture<V> replaceAsync(final K key, final V value, final Metadata metadata, final long explicitFlags, ContextBuilder contextBuilder) {
    assertKeyValueNotNull(key, value);
    ReplaceCommand command = createReplaceCommand(key, value, metadata, explicitFlags);
    return invocationHelper.invokeAsync(contextBuilder, command, 1);
}
Also used : ReplaceCommand(org.infinispan.commands.write.ReplaceCommand)

Aggregations

ReplaceCommand (org.infinispan.commands.write.ReplaceCommand)6 PutKeyValueCommand (org.infinispan.commands.write.PutKeyValueCommand)2 RemoveCommand (org.infinispan.commands.write.RemoveCommand)2 InvocationStage (org.infinispan.interceptors.InvocationStage)2 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 BiFunction (java.util.function.BiFunction)1 Function (java.util.function.Function)1 GetKeyValueCommand (org.infinispan.commands.read.GetKeyValueCommand)1 ClusteredGetCommand (org.infinispan.commands.remote.ClusteredGetCommand)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 ComputeCommand (org.infinispan.commands.write.ComputeCommand)1 ComputeIfAbsentCommand (org.infinispan.commands.write.ComputeIfAbsentCommand)1 DataWriteCommand (org.infinispan.commands.write.DataWriteCommand)1 InvalidateCommand (org.infinispan.commands.write.InvalidateCommand)1 InvalidateL1Command (org.infinispan.commands.write.InvalidateL1Command)1 IracPutKeyValueCommand (org.infinispan.commands.write.IracPutKeyValueCommand)1