Search in sources :

Example 11 with ISet

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

the class ClientTxnSetTest method testAddExistingElement_withinTxn.

@Test
public void testAddExistingElement_withinTxn() throws Exception {
    final String element = "item1";
    final String setName = randomString();
    final ISet set = client.getSet(setName);
    set.add(element);
    final TransactionContext context = client.newTransactionContext();
    context.beginTransaction();
    final TransactionalSet<Object> txnSet = context.getSet(setName);
    assertFalse(txnSet.add(element));
    context.commitTransaction();
    assertEquals(1, set.size());
}
Also used : TransactionContext(com.hazelcast.transaction.TransactionContext) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) ISet(com.hazelcast.core.ISet) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 12 with ISet

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

the class TransactionalSetAbstractTest method testSingleSetAtomicity.

@Test
public void testSingleSetAtomicity() throws ExecutionException, InterruptedException {
    final int itemCount = 200;
    Future<Integer> f = spawn(new Callable<Integer>() {

        @Override
        public Integer call() throws Exception {
            ISet<Object> set = local.getSet(setName);
            while (!set.remove("item-1")) {
            }
            return set.size();
        }
    });
    TransactionContext context = local.newTransactionContext();
    context.beginTransaction();
    TransactionalSet<Object> set = context.getSet(setName);
    for (int i = 0; i < itemCount; i++) {
        set.add("item-" + i);
    }
    context.commitTransaction();
    int size = f.get();
    assertEquals(itemCount - 1, size);
}
Also used : TransactionContext(com.hazelcast.transaction.TransactionContext) ISet(com.hazelcast.core.ISet) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 13 with ISet

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

the class MBeanDestroyTest method testSet.

@Test
public void testSet() throws Exception {
    ISet set = holder.getHz().getSet("set");
    set.size();
    holder.assertMBeanExistEventually("ISet", set.getName());
    destroyObjectAndAssert(set, "ISet");
}
Also used : ISet(com.hazelcast.core.ISet) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

ISet (com.hazelcast.core.ISet)13 Test (org.junit.Test)13 ParallelTest (com.hazelcast.test.annotation.ParallelTest)11 QuickTest (com.hazelcast.test.annotation.QuickTest)11 TransactionContext (com.hazelcast.transaction.TransactionContext)8 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 SetService (com.hazelcast.collection.impl.set.SetService)1 TransactionalTask (com.hazelcast.transaction.TransactionalTask)1 TransactionalTaskContext (com.hazelcast.transaction.TransactionalTaskContext)1 ExecutionException (java.util.concurrent.ExecutionException)1