use of com.hazelcast.collection.IQueue in project hazelcast by hazelcast.
the class SplitBrainProtectionTest method oneSplitBrainProtectionShouldNotAffectSplitBrainProtectionAwareOperationsOnDataStructuresWithoutSplitBrainProtectionConfiguration.
/**
* https://github.com/hazelcast/hazelcast/issues/9792
*/
@Test
public void oneSplitBrainProtectionShouldNotAffectSplitBrainProtectionAwareOperationsOnDataStructuresWithoutSplitBrainProtectionConfiguration() {
String splitBrainProtectionName = randomString();
SplitBrainProtectionConfig splitBrainProtectionConfig = new SplitBrainProtectionConfig(splitBrainProtectionName, true).setFunctionImplementation(new SplitBrainProtectionFunction() {
@Override
public boolean apply(Collection<Member> members) {
return members.size() == 3;
}
});
MapConfig mapConfig = new MapConfig("splitBrainProtectionMap").setSplitBrainProtectionName(splitBrainProtectionName);
Config config = new Config().addMapConfig(mapConfig).addSplitBrainProtectionConfig(splitBrainProtectionConfig);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
HazelcastInstance hz = factory.newHazelcastInstance(config);
factory.newHazelcastInstance(config);
factory.newHazelcastInstance(config);
IMap<Object, Object> splitBrainProtectionMap = hz.getMap("splitBrainProtectionMap");
splitBrainProtectionMap.put(generateKeyOwnedBy(hz), "bar");
IQueue queue = hz.getQueue("noSplitBrainProtectionQueue");
queue.offer("item");
}
use of com.hazelcast.collection.IQueue in project hazelcast by hazelcast.
the class MapTransactionTest method testTransactionAtomicity_withMapAndQueue.
@Test
public void testTransactionAtomicity_withMapAndQueue() throws ExecutionException, InterruptedException {
final HazelcastInstance instance = createHazelcastInstance();
Future<Object> future = spawn(new Callable<Object>() {
@Override
public Object call() throws Exception {
IQueue<Object> queue = instance.getQueue("queue");
IMap<Object, Object> map = instance.getMap("map");
Object item = queue.take();
return map.get(item);
}
});
TransactionOptions options = new TransactionOptions().setTransactionType(TransactionOptions.TransactionType.ONE_PHASE);
TransactionContext context = instance.newTransactionContext(options);
context.beginTransaction();
TransactionalQueue<Object> queue = context.getQueue("queue");
TransactionalMap<Object, Object> map = context.getMap("map");
queue.offer("item-99");
for (int i = 0; i < 100; i++) {
map.put("item-" + i, "value");
}
context.commitTransaction();
assertEquals("value", future.get());
}
Aggregations