use of com.hazelcast.core.MultiMap in project hazelcast by hazelcast.
the class ClientTxnMultiMapTest method testPutAndRoleBack.
@Test
public void testPutAndRoleBack() throws Exception {
final String mapName = randomString();
final String key = "key";
final String value = "value";
final MultiMap multiMap = client.getMultiMap(mapName);
TransactionContext tx = client.newTransactionContext();
tx.beginTransaction();
TransactionalMultiMap mulitMapTxn = tx.getMultiMap(mapName);
mulitMapTxn.put(key, value);
mulitMapTxn.put(key, value);
tx.rollbackTransaction();
assertEquals(0, multiMap.get(key).size());
}
use of com.hazelcast.core.MultiMap in project hazelcast by hazelcast.
the class ClientTxnMultiMapTest method testGet_whenBackedWithList.
@Test
public void testGet_whenBackedWithList() throws Exception {
final String mapName = multiMapBackedByList + randomString();
final String key = "key";
final String value = "value";
final MultiMap multiMap = server.getMultiMap(mapName);
multiMap.put(key, value);
TransactionContext tx = client.newTransactionContext();
tx.beginTransaction();
TransactionalMultiMap mulitMapTxn = tx.getMultiMap(mapName);
Collection c = mulitMapTxn.get(key);
assertFalse(c.isEmpty());
tx.commitTransaction();
}
use of com.hazelcast.core.MultiMap in project Payara by payara.
the class RequestTraceStoreFactory method getStore.
/**
* Generates a request trace store.
*
* @param reservoirSamplingEnabled whether the store should remove items
* based on a reservoir sampling algorithm.
* @param historic whether the store is a historic store or not.
* @return a request trace store.
*/
public static RequestTraceStoreInterface getStore(Events events, boolean reservoirSamplingEnabled, boolean historic) {
// Get the hazelcast store name for if it's a clustered store.
String storeName;
if (historic) {
storeName = HISTORIC_REQUEST_TRACE_STORE;
} else {
storeName = REQUEST_TRACE_STORE;
}
// Determines a strategy for adding items to the store
TraceStorageStrategy strategy;
if (reservoirSamplingEnabled) {
strategy = new ReservoirTraceStorageStrategy();
} else {
strategy = new LongestTraceStorageStrategy();
}
// Get a clustered store if possible
ClusteredStore clusteredStore = Globals.getDefaultHabitat().getService(ClusteredStore.class);
if (clusteredStore != null && clusteredStore.isEnabled()) {
MultiMap<String, RequestTrace> store = (MultiMap) clusteredStore.getMultiMap(storeName);
return new ClusteredRequestTraceStore(store, clusteredStore.getInstanceId(), strategy);
}
// Otherwise get a local store
return new LocalRequestTraceStore(strategy);
}
use of com.hazelcast.core.MultiMap in project hazelcast by hazelcast.
the class ClientMultiMapReduceTest method testAsyncMapperReducer.
@Test(timeout = 120000)
public void testAsyncMapperReducer() throws Exception {
Config config = buildConfig();
HazelcastInstance h1 = hazelcastFactory.newHazelcastInstance(config);
HazelcastInstance h2 = hazelcastFactory.newHazelcastInstance(config);
HazelcastInstance h3 = hazelcastFactory.newHazelcastInstance(config);
assertClusterSizeEventually(3, h1);
assertClusterSizeEventually(3, h2);
assertClusterSizeEventually(3, h3);
HazelcastInstance client = hazelcastFactory.newHazelcastClient();
MultiMap<Integer, Integer> m1 = client.getMultiMap(randomString());
for (int i = 0; i < 100; i++) {
m1.put(i, i);
}
final Map<String, Integer> listenerResults = new HashMap<String, Integer>();
final Semaphore semaphore = new Semaphore(1);
semaphore.acquire();
JobTracker tracker = client.getJobTracker("default");
Job<Integer, Integer> job = tracker.newJob(integerKvSource(m1));
ICompletableFuture<Map<String, Integer>> future = job.mapper(new GroupingTestMapper()).reducer(new TestReducerFactory()).submit();
future.andThen(new ExecutionCallback<Map<String, Integer>>() {
@Override
public void onResponse(Map<String, Integer> response) {
listenerResults.putAll(response);
semaphore.release();
}
@Override
public void onFailure(Throwable t) {
semaphore.release();
}
});
// Precalculate results
int[] expectedResults = new int[4];
for (int i = 0; i < 100; i++) {
int index = i % 4;
expectedResults[index] += i;
}
semaphore.acquire();
for (int i = 0; i < 4; i++) {
assertEquals(expectedResults[i], (int) listenerResults.get(String.valueOf(i)));
}
}
use of com.hazelcast.core.MultiMap in project hazelcast by hazelcast.
the class ClientMultiMapReduceTest method testInProcessCancellation.
@Test(timeout = 60000, expected = CancellationException.class)
public void testInProcessCancellation() throws Exception {
Config config = buildConfig();
HazelcastInstance h1 = hazelcastFactory.newHazelcastInstance(config);
HazelcastInstance h2 = hazelcastFactory.newHazelcastInstance(config);
HazelcastInstance h3 = hazelcastFactory.newHazelcastInstance(config);
assertClusterSizeEventually(3, h1);
assertClusterSizeEventually(3, h2);
assertClusterSizeEventually(3, h3);
HazelcastInstance client = hazelcastFactory.newHazelcastClient();
MultiMap<Integer, Integer> m1 = client.getMultiMap(randomString());
for (int i = 0; i < 100; i++) {
m1.put(i / 2, i);
}
JobTracker tracker = client.getJobTracker("default");
Job<Integer, Integer> job = tracker.newJob(integerKvSource(m1));
ICompletableFuture<Map<String, List<Integer>>> future = job.mapper(new TimeConsumingMapper()).submit();
future.cancel(true);
try {
Map<String, List<Integer>> result = future.get();
fail();
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
Aggregations