Search in sources :

Example 16 with KeyValuePair

use of org.infinispan.util.KeyValuePair in project infinispan by infinispan.

the class AbstractHotRodClusterEventsTest method testParameterBasedConversionInCluster.

public void testParameterBasedConversionInCluster(Method m) {
    HotRodClient client1 = clients().get(0);
    HotRodClient client2 = clients().get(1);
    EventLogListener listener1 = new EventLogListener();
    byte[] convertedKey = new byte[] { 4, 5, 6 };
    Optional<KeyValuePair<String, List<byte[]>>> converteFactory = Optional.of(new KeyValuePair<>("accepted-keyvalue-converter-factory", Collections.singletonList(new byte[] { 4, 5, 6 })));
    withClusterClientListener(client1, listener1, Optional.empty(), converteFactory, null, false, () -> {
        byte[] key1 = k(m, "k1-");
        byte[] value = v(m);
        byte[] key99 = k(m, "k-99");
        client2.put(key99, 0, 0, v(m));
        listener1.expectSingleCustomEvent(anyCache(), addLengthPrefix(key99));
        client2.put(key1, 0, 0, v(m));
        listener1.expectSingleCustomEvent(anyCache(), addLengthPrefix(key1));
        client2.put(convertedKey, 0, 0, v(m));
        listener1.expectSingleCustomEvent(anyCache(), addLengthPrefix(convertedKey, value));
        client1.remove(convertedKey);
        listener1.expectSingleCustomEvent(anyCache(), addLengthPrefix(convertedKey));
    });
}
Also used : KeyValuePair(org.infinispan.util.KeyValuePair) HotRodClient(org.infinispan.server.hotrod.test.HotRodClient)

Example 17 with KeyValuePair

use of org.infinispan.util.KeyValuePair in project infinispan by infinispan.

the class ProtobufMetadataManagerInterceptor method visitPutMapCommand.

@Override
public Object visitPutMapCommand(InvocationContext ctx, PutMapCommand command) {
    if (!ctx.isOriginLocal()) {
        return invokeNext(ctx, command);
    }
    final Map<Object, Object> map = command.getMap();
    FileDescriptorSource source = new FileDescriptorSource();
    for (Object key : map.keySet()) {
        final Object value = map.get(key);
        if (!(key instanceof String)) {
            throw log.keyMustBeString(key.getClass());
        }
        if (!(value instanceof String)) {
            throw log.valueMustBeString(value.getClass());
        }
        if (shouldIntercept(key)) {
            if (!((String) key).endsWith(PROTO_KEY_SUFFIX)) {
                throw log.keyMustBeStringEndingWithProto(key);
            }
            source.addProtoFile((String) key, (String) value);
        }
    }
    // lock global errors key
    VisitableCommand cmd = commandsFactory.buildLockControlCommand(ERRORS_KEY_SUFFIX, command.getFlagsBitSet(), null);
    InvocationStage stage = invoker.running().invokeStage(ctx, cmd);
    return makeStage(asyncInvokeNext(ctx, command, stage)).thenApply(ctx, command, (rCtx, rCommand, rv) -> {
        long flagsBitSet = copyFlags(rCommand);
        ProgressCallback progressCallback = null;
        if (rCtx.isOriginLocal()) {
            progressCallback = new ProgressCallback();
            source.withProgressCallback(progressCallback);
        } else {
            source.withProgressCallback(EMPTY_CALLBACK);
        }
        registerFileDescriptorSource(source, source.getFiles().keySet().toString());
        if (progressCallback != null) {
            List<KeyValuePair<String, String>> errorUpdates = computeErrorUpdates(progressCallback);
            return updateSchemaErrorsIterator(rCtx, flagsBitSet, errorUpdates.iterator());
        }
        return InvocationStage.completedNullStage();
    });
}
Also used : VisitableCommand(org.infinispan.commands.VisitableCommand) InvocationStage(org.infinispan.interceptors.InvocationStage) SyncInvocationStage(org.infinispan.interceptors.SyncInvocationStage) KeyValuePair(org.infinispan.util.KeyValuePair) FileDescriptorSource(org.infinispan.protostream.FileDescriptorSource)

Example 18 with KeyValuePair

use of org.infinispan.util.KeyValuePair in project infinispan by infinispan.

the class ProtobufMetadataManagerInterceptor method computeErrorUpdatesAfterRemove.

private List<KeyValuePair<String, String>> computeErrorUpdatesAfterRemove(String key) {
    // List of proto schemas and their errors
    // Proto schemas with no errors have a null value
    List<KeyValuePair<String, String>> errorUpdates = new ArrayList<>();
    errorUpdates.add(KeyValuePair.of(key, null));
    StringBuilder sb = new StringBuilder();
    for (FileDescriptor fd : serializationContext.getFileDescriptors().values()) {
        String fdName = fd.getName();
        if (fd.isResolved()) {
            errorUpdates.add(KeyValuePair.of(fdName, null));
        } else {
            if (sb.length() > 0) {
                sb.append('\n');
            }
            sb.append(fdName);
            errorUpdates.add(KeyValuePair.of(fdName, "One of the imported files is missing or has errors"));
        }
    }
    errorUpdates.add(KeyValuePair.of("", sb.length() > 0 ? sb.toString() : null));
    return errorUpdates;
}
Also used : KeyValuePair(org.infinispan.util.KeyValuePair) ArrayList(java.util.ArrayList) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor)

Example 19 with KeyValuePair

use of org.infinispan.util.KeyValuePair in project infinispan by infinispan.

the class RemoteApplicationPublishedBridge method readEvent.

protected KeyValuePair<String, Session> readEvent(ClientCacheEntryCustomEvent<byte[]> event) {
    byte[] eventData = event.getEventData();
    ByteBuffer rawData = ByteBuffer.wrap(eventData);
    byte[] rawKey = readElement(rawData);
    byte[] rawValue = readElement(rawData);
    String key = dataFormat.keyToObj(rawKey, allowList);
    KeyValuePair keyValuePair;
    if (rawValue == null) {
        // This events will hold either an old or a new value almost every time. But there are some corner cases
        // during rebalance where neither a new or an old value will be present. This if handles this case
        keyValuePair = new KeyValuePair<>(key, new MapSession(key));
    } else {
        keyValuePair = new KeyValuePair<>(key, dataFormat.valueToObj(rawValue, allowList));
    }
    return keyValuePair;
}
Also used : KeyValuePair(org.infinispan.util.KeyValuePair) MapSession(org.springframework.session.MapSession) ByteBuffer(java.nio.ByteBuffer)

Example 20 with KeyValuePair

use of org.infinispan.util.KeyValuePair in project infinispan by infinispan.

the class RemoteContinuousQueryTest method testContinuousQueryChangingParameter.

public void testContinuousQueryChangingParameter() {
    User user1 = new UserPB();
    user1.setId(1);
    user1.setName("John");
    user1.setSurname("Doe");
    user1.setGender(User.Gender.MALE);
    user1.setAge(22);
    user1.setAccountIds(new HashSet<>(Arrays.asList(1, 2)));
    user1.setNotes("Lorem ipsum dolor sit amet");
    User user2 = new UserPB();
    user2.setId(2);
    user2.setName("Spider");
    user2.setSurname("Man");
    user2.setGender(User.Gender.MALE);
    user2.setAge(32);
    user2.setAccountIds(Collections.singleton(3));
    User user3 = new UserPB();
    user3.setId(3);
    user3.setName("Spider");
    user3.setSurname("Woman");
    user3.setGender(User.Gender.FEMALE);
    user3.setAge(40);
    remoteCache.clear();
    remoteCache.put("user" + user1.getId(), user1);
    remoteCache.put("user" + user2.getId(), user2);
    remoteCache.put("user" + user3.getId(), user3);
    assertEquals(3, remoteCache.size());
    QueryFactory qf = Search.getQueryFactory(remoteCache);
    Query<Object[]> query = qf.<Object[]>create("SELECT age FROM sample_bank_account.User WHERE age <= :ageParam").setParameter("ageParam", 32);
    final BlockingQueue<KeyValuePair<String, Object[]>> joined = new LinkedBlockingQueue<>();
    final BlockingQueue<KeyValuePair<String, Object[]>> updated = new LinkedBlockingQueue<>();
    final BlockingQueue<String> left = new LinkedBlockingQueue<>();
    ContinuousQueryListener<String, Object[]> listener = new ContinuousQueryListener<String, Object[]>() {

        @Override
        public void resultJoining(String key, Object[] value) {
            joined.add(new KeyValuePair<>(key, value));
        }

        @Override
        public void resultUpdated(String key, Object[] value) {
            updated.add(new KeyValuePair<>(key, value));
        }

        @Override
        public void resultLeaving(String key) {
            left.add(key);
        }
    };
    ContinuousQuery<String, User> continuousQuery = Search.getContinuousQuery(remoteCache);
    continuousQuery.addContinuousQueryListener(query, listener);
    expectElementsInQueue(joined, 2, (kv) -> kv.getValue()[0], 32, 22);
    expectElementsInQueue(updated, 0);
    expectElementsInQueue(left, 0);
    continuousQuery.removeContinuousQueryListener(listener);
    query.setParameter("ageParam", 40);
    listener = new ContinuousQueryListener<String, Object[]>() {

        @Override
        public void resultJoining(String key, Object[] value) {
            joined.add(new KeyValuePair<>(key, value));
        }

        @Override
        public void resultUpdated(String key, Object[] value) {
            updated.add(new KeyValuePair<>(key, value));
        }

        @Override
        public void resultLeaving(String key) {
            left.add(key);
        }
    };
    continuousQuery.addContinuousQueryListener(query, listener);
    expectElementsInQueue(joined, 3);
    expectElementsInQueue(updated, 0);
    expectElementsInQueue(left, 0);
    continuousQuery.removeContinuousQueryListener(listener);
}
Also used : QueryFactory(org.infinispan.query.dsl.QueryFactory) User(org.infinispan.query.dsl.embedded.testdomain.User) KeyValuePair(org.infinispan.util.KeyValuePair) ContinuousQueryListener(org.infinispan.query.api.continuous.ContinuousQueryListener) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) UserPB(org.infinispan.client.hotrod.query.testdomain.protobuf.UserPB)

Aggregations

KeyValuePair (org.infinispan.util.KeyValuePair)26 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)8 ArrayList (java.util.ArrayList)7 List (java.util.List)6 UserPB (org.infinispan.client.hotrod.query.testdomain.protobuf.UserPB)6 ContinuousQueryListener (org.infinispan.query.api.continuous.ContinuousQueryListener)6 QueryFactory (org.infinispan.query.dsl.QueryFactory)6 User (org.infinispan.query.dsl.embedded.testdomain.User)6 HotRodClient (org.infinispan.server.hotrod.test.HotRodClient)4 Iterator (java.util.Iterator)3 Map (java.util.Map)3 Set (java.util.Set)3 InvocationStage (org.infinispan.interceptors.InvocationStage)3 SyncInvocationStage (org.infinispan.interceptors.SyncInvocationStage)3 Metadata (org.infinispan.metadata.Metadata)3 Flowable (io.reactivex.rxjava3.core.Flowable)2 ByteBuffer (java.nio.ByteBuffer)2 TreeSet (java.util.TreeSet)2 CompletionStage (java.util.concurrent.CompletionStage)2 Predicate (java.util.function.Predicate)2