Search in sources :

Example 36 with IMap

use of com.hazelcast.map.IMap in project hazelcast by hazelcast.

the class MapChunkTest method smoke.

@Test
public void smoke() {
    Config config = getConfig();
    config.setProperty(ClusterProperty.PARTITION_COUNT.getName(), "1");
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    HazelcastInstance node1 = factory.newHazelcastInstance(config);
    IMap test = node1.getMap("test");
    for (int i = 0; i < 1_000; i++) {
        test.set(i, i);
    }
    HazelcastInstance node2 = factory.newHazelcastInstance(config);
    node1.shutdown();
    assertEquals(1_000, node2.getMap("test").size());
}
Also used : IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 37 with IMap

use of com.hazelcast.map.IMap in project hazelcast by hazelcast.

the class MapTransactionRegressionTest method test_Issue615_KeysetPredicates.

@Test
public void test_Issue615_KeysetPredicates() throws TransactionException {
    final String MAP_NAME = "defaultMap";
    final Config config = getConfig();
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final HazelcastInstance h1 = factory.newHazelcastInstance(config);
    final HazelcastInstance h2 = factory.newHazelcastInstance(config);
    final IMap map = h2.getMap(MAP_NAME);
    final SampleTestObjects.Employee employee1 = new SampleTestObjects.Employee("abc-123-xvz", 34, true, 10D);
    final SampleTestObjects.Employee employee2 = new SampleTestObjects.Employee("abc-1xvz", 4, true, 7D);
    final SampleTestObjects.Employee employee3 = new SampleTestObjects.Employee("abc-1xasda...vz", 7, true, 1D);
    final SampleTestObjects.Employee employee4 = new SampleTestObjects.Employee("abc-1asdsaxvz", 2, true, 2D);
    map.put(employee1, employee1);
    final TransactionContext context = h1.newTransactionContext();
    context.beginTransaction();
    final TransactionalMap<Object, Object> txMap = context.getMap(MAP_NAME);
    assertNull(txMap.put(employee2, employee2));
    assertEquals(2, txMap.size());
    assertEquals(2, txMap.keySet().size());
    assertEquals(1, txMap.keySet(Predicates.sql("age = 34")).size());
    context.commitTransaction();
    assertEquals(2, map.size());
    h1.shutdown();
    h2.shutdown();
}
Also used : IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) TransactionContext(com.hazelcast.transaction.TransactionContext) SampleTestObjects(com.hazelcast.query.SampleTestObjects) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 38 with IMap

use of com.hazelcast.map.IMap in project hazelcast by hazelcast.

the class MapTransactionRegressionTest method test_Issue615_KeysetWithPredicate.

@Test
public void test_Issue615_KeysetWithPredicate() throws TransactionException {
    Config config = getConfig();
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final HazelcastInstance h1 = factory.newHazelcastInstance(config);
    final HazelcastInstance h2 = factory.newHazelcastInstance(config);
    final IMap map = h2.getMap("default");
    final SampleTestObjects.Employee employee1 = new SampleTestObjects.Employee("abc-123-xvz", 34, true, 10D);
    final SampleTestObjects.Employee employee2 = new SampleTestObjects.Employee("abc-1xvz", 4, true, 7D);
    final SampleTestObjects.Employee employee3 = new SampleTestObjects.Employee("abc-1xasda...vz", 7, true, 1D);
    final SampleTestObjects.Employee employee4 = new SampleTestObjects.Employee("abc-1asdsaxvz", 2, true, 2D);
    map.put(1, employee1);
    try {
        h1.executeTransaction(options, (context) -> {
            final TransactionalMap<Object, Object> txMap = context.getMap("default");
            assertEquals(0, txMap.keySet(Predicates.sql("age <= 10")).size());
            // put
            txMap.put(2, employee2);
            Set keys = txMap.keySet(Predicates.sql("age <= 10"));
            Iterator iterator = keys.iterator();
            assertEquals(1, keys.size());
            while (iterator.hasNext()) {
                assertEquals(2, ((Integer) iterator.next()).intValue());
            }
            txMap.put(3, employee3);
            txMap.put(4, employee4);
            keys = txMap.keySet(Predicates.sql("age <= 10"));
            assertEquals(3, keys.size());
            // force rollback.
            throw new DummyUncheckedHazelcastTestException();
        });
    } catch (Exception e) {
        if (!(e instanceof DummyUncheckedHazelcastTestException)) {
            throw new RuntimeException(e);
        }
    }
    assertEquals(1, map.size());
    assertEquals(1, map.keySet().size());
    assertEquals(0, map.keySet(Predicates.sql("age <= 10")).size());
    h1.shutdown();
    h2.shutdown();
}
Also used : Set(java.util.Set) Config(com.hazelcast.config.Config) TransactionException(com.hazelcast.transaction.TransactionException) IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) SampleTestObjects(com.hazelcast.query.SampleTestObjects) Iterator(java.util.Iterator) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 39 with IMap

use of com.hazelcast.map.IMap in project hazelcast by hazelcast.

the class MapTransactionRegressionTest method test_Issue1076.

@Test
public void test_Issue1076() {
    Config config = getConfig();
    final HazelcastInstance inst = createHazelcastInstance(config);
    IMap map = inst.getMap("default");
    EntryListener<String, Integer> l = new EntryAdapter<String, Integer>() {
    };
    EntryObject e = Predicates.newPredicateBuilder().getEntryObject();
    Predicate<String, Integer> p = e.get("this").equal(1);
    map.addEntryListener(l, p, null, false);
    for (Integer i = 0; i < 100; i++) {
        TransactionContext context = inst.newTransactionContext();
        context.beginTransaction();
        TransactionalMap<String, Integer> txnMap = context.getMap("default");
        txnMap.remove(i.toString());
        context.commitTransaction();
    }
    assertEquals(0, map.size());
    inst.shutdown();
}
Also used : IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) Config(com.hazelcast.config.Config) TransactionContext(com.hazelcast.transaction.TransactionContext) EntryAdapter(com.hazelcast.core.EntryAdapter) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 40 with IMap

use of com.hazelcast.map.IMap in project hazelcast by hazelcast.

the class MapTransactionTest method testValues_resultSetContainsUpdatedEntry.

@Test
public void testValues_resultSetContainsUpdatedEntry() throws TransactionException {
    final int nodeCount = 1;
    final String mapName = randomMapName();
    final Config config = getConfig();
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
    final HazelcastInstance node = factory.newHazelcastInstance(config);
    final IMap map = node.getMap(mapName);
    final Employee emp = new Employee("name", 77, true, 10D);
    map.put(1, emp);
    node.executeTransaction(options, new TransactionalTask<Boolean>() {

        public Boolean execute(TransactionalTaskContext context) throws TransactionException {
            final TransactionalMap<Integer, Employee> txMap = context.getMap(mapName);
            emp.setAge(30);
            txMap.put(1, emp);
            Collection<Employee> coll = txMap.values();
            assertEquals(1, coll.size());
            Employee employee = coll.iterator().next();
            assertEquals(30, employee.getAge());
            return true;
        }
    });
    node.shutdown();
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleTestObjects.Employee) TransactionException(com.hazelcast.transaction.TransactionException) Collection(java.util.Collection) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Aggregations

IMap (com.hazelcast.map.IMap)294 Test (org.junit.Test)259 QuickTest (com.hazelcast.test.annotation.QuickTest)237 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)228 HazelcastInstance (com.hazelcast.core.HazelcastInstance)139 Config (com.hazelcast.config.Config)103 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)82 Map (java.util.Map)75 CountDownLatch (java.util.concurrent.CountDownLatch)65 MapStoreConfig (com.hazelcast.config.MapStoreConfig)54 Category (org.junit.experimental.categories.Category)51 Assert.assertEquals (org.junit.Assert.assertEquals)50 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)48 HashMap (java.util.HashMap)48 Collection (java.util.Collection)41 RunWith (org.junit.runner.RunWith)41 MapConfig (com.hazelcast.config.MapConfig)36 Set (java.util.Set)34 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)33 AssertTask (com.hazelcast.test.AssertTask)32