Search in sources :

Example 16 with IQueue

use of com.hazelcast.core.IQueue in project hazelcast by hazelcast.

the class MBeanTest method testQueue.

@Test
public void testQueue() throws Exception {
    IQueue queue = holder.getHz().getQueue("queue");
    queue.size();
    holder.assertMBeanExistEventually("IQueue", queue.getName());
}
Also used : IQueue(com.hazelcast.core.IQueue) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 17 with IQueue

use of com.hazelcast.core.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.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IQueue(com.hazelcast.core.IQueue) TransactionOptions(com.hazelcast.transaction.TransactionOptions) TransactionContext(com.hazelcast.transaction.TransactionContext) Mockito.anyObject(org.mockito.Mockito.anyObject) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

IQueue (com.hazelcast.core.IQueue)17 ParallelTest (com.hazelcast.test.annotation.ParallelTest)15 QuickTest (com.hazelcast.test.annotation.QuickTest)15 Test (org.junit.Test)15 TransactionContext (com.hazelcast.transaction.TransactionContext)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)6 TransactionalQueue (com.hazelcast.core.TransactionalQueue)4 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)2 TransactionException (com.hazelcast.transaction.TransactionException)2 TransactionNotActiveException (com.hazelcast.transaction.TransactionNotActiveException)2 ExecutionException (java.util.concurrent.ExecutionException)2 QueueService (com.hazelcast.collection.impl.queue.QueueService)1 IMap (com.hazelcast.core.IMap)1 ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 NightlyTest (com.hazelcast.test.annotation.NightlyTest)1 TransactionOptions (com.hazelcast.transaction.TransactionOptions)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1