Search in sources :

Example 26 with IMap

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

the class ClientMaxAllowedInvocationTest method testMaxAllowed_withSyncOperation.

@Test(expected = HazelcastOverloadException.class)
public void testMaxAllowed_withSyncOperation() {
    int MAX_ALLOWED = 10;
    hazelcastFactory.newHazelcastInstance();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setProperty(ClientProperty.MAX_CONCURRENT_INVOCATIONS.getName(), String.valueOf(MAX_ALLOWED));
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    IMap map = client.getMap(randomString());
    IExecutorService executorService = client.getExecutorService(randomString());
    for (int i = 0; i < MAX_ALLOWED; i++) {
        executorService.submit(new SleepyProcessor(Integer.MAX_VALUE));
    }
    map.get(2);
}
Also used : IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IExecutorService(com.hazelcast.core.IExecutorService) ClientConfig(com.hazelcast.client.config.ClientConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 27 with IMap

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

the class WriteMapP method init.

@Override
public void init(@Nonnull Outbox outbox, @Nonnull Context context) {
    map = instance().getMap(mapName);
    boolean hasCustomSerializers = serializationService instanceof DelegatingSerializationService && ((DelegatingSerializationService) serializationService).hasAddedSerializers();
    boolean hasNearCache = map instanceof NearCachedMapProxyImpl;
    if (hasNearCache && hasCustomSerializers) {
        // See https://github.com/hazelcast/hazelcast-jet/issues/3046
        throw new JetException("Writing into IMap with both near cache and custom serializers not supported");
    }
    if (!hasCustomSerializers) {
        addToBuffer = item -> buffer.add(new SimpleEntry<>(key(item), value(item)));
    } else if (map instanceof MapProxyImpl) {
        PartitioningStrategy<?> partitionStrategy = ((MapProxyImpl<K, V>) map).getPartitionStrategy();
        addToBuffer = item -> {
            Data key = serializationService.toData(key(item), partitionStrategy);
            Data value = serializationService.toData(value(item));
            buffer.add(new SimpleEntry<>(key, value));
        };
    } else if (map instanceof ClientMapProxy) {
        // TODO: add strategy/unify after https://github.com/hazelcast/hazelcast/issues/13950 is fixed
        addToBuffer = item -> {
            Data key = serializationService.toData(key(item));
            Data value = serializationService.toData(value(item));
            buffer.add(new SimpleEntry<>(key, value));
        };
    } else {
        throw new RuntimeException("Unexpected map class: " + map.getClass().getName());
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) FunctionEx(com.hazelcast.function.FunctionEx) EdgeConfig(com.hazelcast.jet.config.EdgeConfig) DelegatingSerializationService(com.hazelcast.jet.impl.serialization.DelegatingSerializationService) NearCachedMapProxyImpl(com.hazelcast.map.impl.proxy.NearCachedMapProxyImpl) PartitioningStrategy(com.hazelcast.partition.PartitioningStrategy) Outbox(com.hazelcast.jet.core.Outbox) Data(com.hazelcast.internal.serialization.Data) Processor(com.hazelcast.jet.core.Processor) Collections.singletonList(java.util.Collections.singletonList) JetException(com.hazelcast.jet.JetException) Consumer(java.util.function.Consumer) ArrayMap(com.hazelcast.jet.impl.connector.HazelcastWriters.ArrayMap) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) PermissionsUtil.mapPutPermission(com.hazelcast.security.PermissionsUtil.mapPutPermission) Integer.max(java.lang.Integer.max) List(java.util.List) Permission(java.security.Permission) SerializationService(com.hazelcast.internal.serialization.SerializationService) ClientMapProxy(com.hazelcast.client.impl.proxy.ClientMapProxy) Inbox(com.hazelcast.jet.core.Inbox) Nonnull(javax.annotation.Nonnull) SimpleEntry(java.util.AbstractMap.SimpleEntry) IMap(com.hazelcast.map.IMap) DelegatingSerializationService(com.hazelcast.jet.impl.serialization.DelegatingSerializationService) SimpleEntry(java.util.AbstractMap.SimpleEntry) NearCachedMapProxyImpl(com.hazelcast.map.impl.proxy.NearCachedMapProxyImpl) Data(com.hazelcast.internal.serialization.Data) JetException(com.hazelcast.jet.JetException) ClientMapProxy(com.hazelcast.client.impl.proxy.ClientMapProxy) NearCachedMapProxyImpl(com.hazelcast.map.impl.proxy.NearCachedMapProxyImpl) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) PartitioningStrategy(com.hazelcast.partition.PartitioningStrategy)

Example 28 with IMap

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

the class ClientRegressionWithRealNetworkTest method testListenersAfterClientDisconnected.

private void testListenersAfterClientDisconnected(String memberAddress, String clientAddress) {
    Config config = new Config();
    int heartBeatSeconds = 6;
    config.getNetworkConfig().setPublicAddress(memberAddress);
    config.setProperty(ClusterProperty.CLIENT_HEARTBEAT_TIMEOUT_SECONDS.getName(), Integer.toString(heartBeatSeconds));
    HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
    ClientConfig clientConfig = new ClientConfig();
    ClientNetworkConfig networkConfig = clientConfig.getNetworkConfig();
    networkConfig.addAddress(clientAddress);
    clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
    HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
    IMap<Integer, Integer> map = client.getMap("test");
    AtomicInteger eventCount = new AtomicInteger(0);
    map.addEntryListener((EntryAddedListener<Object, Object>) event -> eventCount.incrementAndGet(), false);
    assertTrueEventually(() -> {
        HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
        int size = clientInstanceImpl.getConnectionManager().getActiveConnections().size();
        assertEquals(1, size);
    });
    hazelcastInstance.shutdown();
    sleepAtLeastSeconds(2 * heartBeatSeconds);
    Hazelcast.newHazelcastInstance(config);
    assertTrueEventually(() -> {
        map.remove(1);
        map.put(1, 2);
        assertNotEquals(0, eventCount.get());
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) Address(com.hazelcast.cluster.Address) ClientTestSupport(com.hazelcast.client.test.ClientTestSupport) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) ClientProperty(com.hazelcast.client.properties.ClientProperty) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) After(org.junit.After) ClientConfig(com.hazelcast.client.config.ClientConfig) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) ExecutorService(java.util.concurrent.ExecutorService) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AddressProvider(com.hazelcast.client.impl.connection.AddressProvider) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest) UUID(java.util.UUID) TcpClientConnectionManager(com.hazelcast.client.impl.connection.tcp.TcpClientConnectionManager) Category(org.junit.experimental.categories.Category) AddressHelper(com.hazelcast.client.util.AddressHelper) Executors(java.util.concurrent.Executors) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) EntryAddedListener(com.hazelcast.map.listener.EntryAddedListener) ClusterProperty(com.hazelcast.spi.properties.ClusterProperty) CountDownLatch(java.util.concurrent.CountDownLatch) Addresses(com.hazelcast.client.impl.connection.Addresses) ClientConnectionStrategyConfig(com.hazelcast.client.config.ClientConnectionStrategyConfig) Assert.assertNull(org.junit.Assert.assertNull) Hazelcast(com.hazelcast.core.Hazelcast) Assert.assertEquals(org.junit.Assert.assertEquals) ClientConnectionManager(com.hazelcast.client.impl.connection.ClientConnectionManager) IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientConfig(com.hazelcast.client.config.ClientConfig) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) Config(com.hazelcast.config.Config) ClientConnectionStrategyConfig(com.hazelcast.client.config.ClientConnectionStrategyConfig) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientConfig(com.hazelcast.client.config.ClientConfig) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig)

Example 29 with IMap

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

the class SqlSplitBrainTest method test_indexScan.

@Test
public // test for https://github.com/hazelcast/hazelcast/issues/19472
void test_indexScan() throws InterruptedException {
    Thread[] threads = new Thread[2];
    AtomicBoolean done = new AtomicBoolean();
    AtomicInteger numQueries = new AtomicInteger();
    Consumer<HazelcastInstance[]> beforeSplit = instances -> {
        IMap<Integer, Integer> m = instances[0].getMap("m");
        for (int i = 0; i < 10_000; i++) {
            m.put(i, i);
        }
        m.addIndex(new IndexConfig().addAttribute("this"));
        SqlTestSupport.createMapping(instances[0], "m", Integer.class, Integer.class);
        for (int i = 0, threadsLength = threads.length; i < threadsLength; i++) {
            HazelcastInstance inst = createHazelcastClient();
            threads[i] = new Thread(() -> {
                int numQueriesLocal = 0;
                while (!done.get()) {
                    try {
                        // noinspection StatementWithEmptyBody
                        for (SqlRow ignored : inst.getSql().execute("select * from m where this>100 and this<1000")) {
                        // do nothing
                        }
                    } catch (Throwable e) {
                        logger.info(e);
                    }
                    numQueriesLocal++;
                }
                numQueries.addAndGet(numQueriesLocal);
            });
            threads[i].start();
            sleepSeconds(1);
        }
    };
    testSplitBrain(1, 1, beforeSplit, null, null);
    done.set(true);
    boolean stuck = false;
    for (Thread t : threads) {
        t.join(5000);
        if (t.isAlive()) {
            logger.info("thread " + t + " stuck");
            stuck = true;
        }
    }
    logger.info("num queries executed: " + numQueries.get());
    if (stuck) {
        fail("some threads were stuck");
    }
}
Also used : Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NightlyTest(com.hazelcast.test.annotation.NightlyTest) RunWith(org.junit.runner.RunWith) MAX_BACKUP_COUNT(com.hazelcast.internal.partition.IPartition.MAX_BACKUP_COUNT) SqlTestSupport(com.hazelcast.jet.sql.SqlTestSupport) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) IndexConfig(com.hazelcast.config.IndexConfig) Consumer(java.util.function.Consumer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JetSplitBrainTestSupport(com.hazelcast.jet.core.JetSplitBrainTestSupport) Assert.fail(org.junit.Assert.fail) SqlRow(com.hazelcast.sql.SqlRow) IMap(com.hazelcast.map.IMap) SqlRow(com.hazelcast.sql.SqlRow) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IMap(com.hazelcast.map.IMap) IndexConfig(com.hazelcast.config.IndexConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 30 with IMap

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

the class SqlSelectTest method test_selectWithEvenNumbersFilter.

@Test
public void test_selectWithEvenNumbersFilter() {
    HazelcastInstance hazelcastInstance = instance();
    String name = randomName();
    createMapping(name, int.class, String.class);
    IMap<Integer, String> map = hazelcastInstance.getMap(name);
    List<Row> rows = fillIMapAndGetData(map, 14);
    List<Row> filteredRows = rows.stream().filter(row -> ((int) row.getValues()[0] % 2 == 0)).collect(toList());
    assertRowsAnyOrder("SELECT * FROM " + name + " WHERE ( __key % 2 ) = 0", filteredRows);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) BeforeClass(org.junit.BeforeClass) QuickTest(com.hazelcast.test.annotation.QuickTest) SqlTestSupport(com.hazelcast.jet.sql.SqlTestSupport) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) 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