Search in sources :

Example 66 with MultiMap

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());
}
Also used : MultiMap(com.hazelcast.core.MultiMap) TransactionalMultiMap(com.hazelcast.core.TransactionalMultiMap) TransactionContext(com.hazelcast.transaction.TransactionContext) TransactionalMultiMap(com.hazelcast.core.TransactionalMultiMap) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 67 with MultiMap

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();
}
Also used : MultiMap(com.hazelcast.core.MultiMap) TransactionalMultiMap(com.hazelcast.core.TransactionalMultiMap) TransactionContext(com.hazelcast.transaction.TransactionContext) TransactionalMultiMap(com.hazelcast.core.TransactionalMultiMap) Collection(java.util.Collection) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 68 with MultiMap

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);
}
Also used : MultiMap(com.hazelcast.core.MultiMap) TraceStorageStrategy(fish.payara.nucleus.requesttracing.store.strategy.TraceStorageStrategy) ReservoirTraceStorageStrategy(fish.payara.nucleus.requesttracing.store.strategy.ReservoirTraceStorageStrategy) LongestTraceStorageStrategy(fish.payara.nucleus.requesttracing.store.strategy.LongestTraceStorageStrategy) ClusteredStore(fish.payara.nucleus.store.ClusteredStore) LongestTraceStorageStrategy(fish.payara.nucleus.requesttracing.store.strategy.LongestTraceStorageStrategy) RequestTrace(fish.payara.notification.requesttracing.RequestTrace) ReservoirTraceStorageStrategy(fish.payara.nucleus.requesttracing.store.strategy.ReservoirTraceStorageStrategy)

Example 69 with MultiMap

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)));
    }
}
Also used : HashMap(java.util.HashMap) Config(com.hazelcast.config.Config) JobTracker(com.hazelcast.mapreduce.JobTracker) Semaphore(java.util.concurrent.Semaphore) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HashMap(java.util.HashMap) MultiMap(com.hazelcast.core.MultiMap) Map(java.util.Map) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 70 with MultiMap

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;
    }
}
Also used : Config(com.hazelcast.config.Config) JobTracker(com.hazelcast.mapreduce.JobTracker) CancellationException(java.util.concurrent.CancellationException) ExecutionException(java.util.concurrent.ExecutionException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) List(java.util.List) HashMap(java.util.HashMap) MultiMap(com.hazelcast.core.MultiMap) Map(java.util.Map) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Aggregations

MultiMap (com.hazelcast.core.MultiMap)118 Test (org.junit.Test)117 QuickTest (com.hazelcast.test.annotation.QuickTest)107 ParallelTest (com.hazelcast.test.annotation.ParallelTest)106 HazelcastInstance (com.hazelcast.core.HazelcastInstance)16 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)12 Map (java.util.Map)11 Config (com.hazelcast.config.Config)9 TransactionalMultiMap (com.hazelcast.core.TransactionalMultiMap)9 JobTracker (com.hazelcast.mapreduce.JobTracker)9 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)9 HashMap (java.util.HashMap)9 TransactionContext (com.hazelcast.transaction.TransactionContext)8 SlowTest (com.hazelcast.test.annotation.SlowTest)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 AssertTask (com.hazelcast.test.AssertTask)5 Collection (java.util.Collection)5 List (java.util.List)5 Set (java.util.Set)4 TreeSet (java.util.TreeSet)4