Search in sources :

Example 16 with IQueue

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");
}
Also used : MapConfig(com.hazelcast.config.MapConfig) SplitBrainProtectionConfig(com.hazelcast.config.SplitBrainProtectionConfig) Config(com.hazelcast.config.Config) SplitBrainProtectionConfig(com.hazelcast.config.SplitBrainProtectionConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IQueue(com.hazelcast.collection.IQueue) RecentlyActiveSplitBrainProtectionFunction(com.hazelcast.splitbrainprotection.impl.RecentlyActiveSplitBrainProtectionFunction) ProbabilisticSplitBrainProtectionFunction(com.hazelcast.splitbrainprotection.impl.ProbabilisticSplitBrainProtectionFunction) MapConfig(com.hazelcast.config.MapConfig) Member(com.hazelcast.cluster.Member) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 17 with IQueue

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());
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TransactionException(com.hazelcast.transaction.TransactionException) ExecutionException(java.util.concurrent.ExecutionException) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) TransactionNotActiveException(com.hazelcast.transaction.TransactionNotActiveException) IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IQueue(com.hazelcast.collection.IQueue) TransactionOptions(com.hazelcast.transaction.TransactionOptions) TransactionContext(com.hazelcast.transaction.TransactionContext) Mockito.anyObject(org.mockito.Mockito.anyObject) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Aggregations

IQueue (com.hazelcast.collection.IQueue)17 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)16 QuickTest (com.hazelcast.test.annotation.QuickTest)16 Test (org.junit.Test)16 TransactionContext (com.hazelcast.transaction.TransactionContext)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)6 TransactionalQueue (com.hazelcast.transaction.TransactionalQueue)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 Config (com.hazelcast.config.Config)4 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)3 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)2 OperationTimeoutException (com.hazelcast.core.OperationTimeoutException)2 TransactionException (com.hazelcast.transaction.TransactionException)2 TransactionNotActiveException (com.hazelcast.transaction.TransactionNotActiveException)2 TransactionOptions (com.hazelcast.transaction.TransactionOptions)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 Member (com.hazelcast.cluster.Member)1 ItemEvent (com.hazelcast.collection.ItemEvent)1