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());
}
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());
}
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());
}
}
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()));
}
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");
}
Aggregations