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));
});
}
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();
});
}
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;
}
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;
}
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);
}
Aggregations