Search in sources :

Example 1 with ISet

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

the class ClientTxnSetTest method testSetSizeAfterAddingDuplicateElement_withinTxn.

@Test
public void testSetSizeAfterAddingDuplicateElement_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);
    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 2 with ISet

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

the class ClientTxnSetTest method testSetSizeAfterRemove_withinTxn.

@Test
public void testSetSizeAfterRemove_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);
    txnSet.remove(element);
    context.commitTransaction();
    assertEquals(0, 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 3 with ISet

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

the class SetAbstractTest method testNameBasedAffinity.

@Test
public void testNameBasedAffinity() {
    //creates more instances to increase a chance 'foo' will not be owned by
    //the same member as 'foo@1'
    newInstances(config);
    newInstances(config);
    int numberOfSets = 100;
    ISet[] localSets = new ISet[numberOfSets];
    ISet[] targetSets = new ISet[numberOfSets];
    for (int i = 0; i < numberOfSets; i++) {
        String name = randomName() + "@" + i;
        localSets[i] = local.getSet(name);
        targetSets[i] = target.getSet(name);
    }
    for (final ISet set : localSets) {
        TransactionalTask task = new TransactionalTask() {

            @Override
            public Object execute(TransactionalTaskContext context) throws TransactionException {
                TransactionalSet<String> txSet = context.getSet(set.getName());
                txSet.add("Hello");
                return null;
            }
        };
        local.executeTransaction(task);
    }
    for (ISet set : localSets) {
        assertEquals(1, set.size());
    }
}
Also used : TransactionalTask(com.hazelcast.transaction.TransactionalTask) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) ISet(com.hazelcast.core.ISet) Test(org.junit.Test)

Example 4 with ISet

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

the class PartitionControlledIdTest method testSet.

@Test
public void testSet() throws Exception {
    String partitionKey = "hazelcast";
    HazelcastInstance hz = getHazelcastInstance(partitionKey);
    ISet set = hz.getSet("set@" + partitionKey);
    set.add("");
    assertEquals("set@" + partitionKey, set.getName());
    assertEquals(partitionKey, set.getPartitionKey());
    SetService service = getNodeEngine(hz).getService(SetService.SERVICE_NAME);
    assertTrue(service.getContainerMap().containsKey(set.getName()));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) SetService(com.hazelcast.collection.impl.set.SetService) ISet(com.hazelcast.core.ISet) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with ISet

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

the class HazelcastOSGiInstanceTest method getSetCalledSuccessfullyOverOSGiInstance.

@Test
public void getSetCalledSuccessfullyOverOSGiInstance() {
    ISet mockSet = mock(ISet.class);
    HazelcastInstance mockHazelcastInstance = mock(HazelcastInstance.class);
    HazelcastOSGiInstance hazelcastOSGiInstance = HazelcastOSGiTestUtil.createHazelcastOSGiInstance(mockHazelcastInstance);
    when(mockHazelcastInstance.getSet("my-set")).thenReturn(mockSet);
    assertEquals(mockSet, hazelcastOSGiInstance.getSet("my-set"));
    verify(mockHazelcastInstance).getSet("my-set");
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) 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