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