use of com.hazelcast.config.XmlConfigBuilder in project hazelcast by hazelcast.
the class MemberToMemberDiscoveryTest method invalidPortPropertyTest.
@Test(expected = ValidationException.class)
public void invalidPortPropertyTest() throws InterruptedException {
String xmlFileName = "hazelcast-multicast-plugin-invalid-port.xml";
InputStream xmlResource = MulticastDiscoveryStrategy.class.getClassLoader().getResourceAsStream(xmlFileName);
config = new XmlConfigBuilder(xmlResource).build();
factory.newInstances(config);
}
use of com.hazelcast.config.XmlConfigBuilder in project hazelcast by hazelcast.
the class MapStoreDataLoadingContinuesWhenNodeJoins method testNoDeadLockDuringJoin.
@Test(timeout = 600000)
public void testNoDeadLockDuringJoin() throws Exception {
// create shared hazelcast config
final Config config = new XmlConfigBuilder().build();
// disable JMX to make sure lazy loading works asynchronously
config.setProperty("hazelcast.jmx", "false");
// get map config
MapConfig mapConfig = config.getMapConfig(MAP_NAME);
// create shared map store implementation
// - use slow loading (300ms per map entry)
final CountDownLatch halfOfKeysAreLoaded = new CountDownLatch(1);
final InMemoryMapStore store = new InMemoryMapStore(halfOfKeysAreLoaded, MS_PER_LOAD, false);
store.preload(PRELOAD_SIZE);
// configure map store
MapStoreConfig mapStoreConfig = new MapStoreConfig();
mapStoreConfig.setEnabled(true);
mapStoreConfig.setInitialLoadMode(InitialLoadMode.LAZY);
mapStoreConfig.setWriteDelaySeconds(WRITE_DELAY_SECONDS);
mapStoreConfig.setClassName(null);
mapStoreConfig.setImplementation(store);
mapConfig.setMapStoreConfig(mapStoreConfig);
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
final CountDownLatch node1Started = new CountDownLatch(1);
final CountDownLatch node1FinishedLoading = new CountDownLatch(1);
// thread 1:
// start a single node and load the data
Thread thread1 = new Thread(new Runnable() {
@Override
public void run() {
HazelcastInstance hcInstance = factory.newHazelcastInstance(config);
// try-finally to stop hazelcast instance
node1Started.countDown();
try {
// get map
// this will trigger loading the data
IMap<String, String> map = hcInstance.getMap(MAP_NAME);
map.size();
node1FinishedLoading.countDown();
} finally {
thread1Shutdown.set(System.currentTimeMillis());
hcInstance.getLifecycleService().shutdown();
}
}
}, "Thread 1");
thread1.start();
node1Started.await();
// thread 2:
// simulate a second member which joins the cluster
Thread thread2 = new Thread(new Runnable() {
@Override
public void run() {
HazelcastInstance hcInstance = factory.newHazelcastInstance(config);
try {
hcInstance.getMap(MAP_NAME);
final int loadTimeMillis = MS_PER_LOAD * PRELOAD_SIZE;
node1FinishedLoading.await(loadTimeMillis, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
EmptyStatement.ignore(e);
} finally {
thread2Shutdown.set(System.currentTimeMillis());
hcInstance.getLifecycleService().shutdown();
}
}
}, "Thread 2");
thread2.start();
// join threads
thread1.join();
thread2.join();
// assert correct shutdown order
if (thread1Shutdown.get() > thread2Shutdown.get()) {
fail("Thread 2 was shutdown before thread 1.");
}
}
use of com.hazelcast.config.XmlConfigBuilder in project hazelcast by hazelcast.
the class MapStoreDataLoadingContinuesWhenNodeJoins method testDataLoadedCorrectly.
@Test(timeout = 600000)
public void testDataLoadedCorrectly() throws Exception {
// create shared hazelcast config
final Config config = new XmlConfigBuilder().build();
// disable JMX to make sure lazy loading works asynchronously
config.setProperty("hazelcast.jmx", "false");
// get map config
MapConfig mapConfig = config.getMapConfig(MAP_NAME);
// create shared map store implementation
// - use slow loading (300ms per map entry)
final CountDownLatch halfOfKeysAreLoaded = new CountDownLatch(1);
final InMemoryMapStore store = new InMemoryMapStore(halfOfKeysAreLoaded, 300, false);
store.preload(PRELOAD_SIZE);
// configure map store
MapStoreConfig mapStoreConfig = new MapStoreConfig();
mapStoreConfig.setEnabled(true);
mapStoreConfig.setInitialLoadMode(InitialLoadMode.LAZY);
mapStoreConfig.setWriteDelaySeconds(WRITE_DELAY_SECONDS);
mapStoreConfig.setClassName(null);
mapStoreConfig.setImplementation(store);
mapConfig.setMapStoreConfig(mapStoreConfig);
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
final CountDownLatch node1Started = new CountDownLatch(1);
final CountDownLatch node1FinishedLoading = new CountDownLatch(1);
// thread 1:
// start a single node and load the data
Thread thread1 = new Thread(new Runnable() {
@Override
public void run() {
HazelcastInstance instance = factory.newHazelcastInstance(config);
// try-finally to stop hazelcast instance
node1Started.countDown();
try {
// get map
// this will trigger loading the data
final IMap<String, String> map = instance.getMap(MAP_NAME);
mapSize.set(map.size());
node1FinishedLoading.countDown();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(PRELOAD_SIZE, map.size());
}
}, 5);
// -------------------------------------------------- {20s}
} finally {
instance.getLifecycleService().shutdown();
}
}
}, "Thread 1");
thread1.start();
// wait 10s after starting first thread
node1Started.await();
// thread 2:
// simulate a second member which joins the cluster
Thread thread2 = new Thread(new Runnable() {
@Override
public void run() {
HazelcastInstance instance = factory.newHazelcastInstance(config);
// try-finally to stop hazelcast instance
try {
// get map
instance.getMap(MAP_NAME);
final int loadTimeMillis = MS_PER_LOAD * PRELOAD_SIZE;
node1FinishedLoading.await(loadTimeMillis, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
EmptyStatement.ignore(e);
} finally {
instance.getLifecycleService().shutdown();
}
}
}, "Thread 2");
if (SIMULATE_SECOND_NODE) {
thread2.start();
}
// join threads
thread1.join();
if (SIMULATE_SECOND_NODE) {
thread2.join();
}
}
use of com.hazelcast.config.XmlConfigBuilder in project hazelcast by hazelcast.
the class MapStoreTest method testReadingConfiguration.
@Test(timeout = 120000)
public void testReadingConfiguration() throws Exception {
String mapName = "mapstore-test";
InputStream is = getClass().getResourceAsStream("/com/hazelcast/config/hazelcast-mapstore-config.xml");
XmlConfigBuilder builder = new XmlConfigBuilder(is);
Config config = builder.build();
HazelcastInstance hz = createHazelcastInstance(config);
MapProxyImpl map = (MapProxyImpl) hz.getMap(mapName);
MapService mapService = (MapService) map.getService();
MapContainer mapContainer = mapService.getMapServiceContext().getMapContainer(mapName);
MapStoreWrapper mapStoreWrapper = mapContainer.getMapStoreContext().getMapStoreWrapper();
Iterator keys = mapStoreWrapper.loadAllKeys().iterator();
final Set<String> loadedKeySet = loadedKeySet(keys);
final Set<String> expectedKeySet = expectedKeySet();
assertEquals(expectedKeySet, loadedKeySet);
assertEquals("true", mapStoreWrapper.load("my-prop-1"));
assertEquals("foo", mapStoreWrapper.load("my-prop-2"));
}
use of com.hazelcast.config.XmlConfigBuilder in project hazelcast by hazelcast.
the class ClientMapWithIndexCreationTest method test_createMapWithIndexes_whenProxyCreatedOnMemberOtherThanClientOwner.
/**
* Given a two members (A, B) cluster, a non-smart client connected to B attempts to create a map proxy targeting member A.
*/
@Test
public void test_createMapWithIndexes_whenProxyCreatedOnMemberOtherThanClientOwner() {
Config config = new XmlConfigBuilder().build();
MapConfig mapConfig = config.getMapConfig("test");
List<MapIndexConfig> mapIndexConfigs = mapConfig.getMapIndexConfigs();
MapIndexConfig mapIndexConfig = new MapIndexConfig();
mapIndexConfig.setAttribute("name");
mapIndexConfig.setOrdered(true);
mapIndexConfigs.add(mapIndexConfig);
HazelcastInstance hz1 = factory.newHazelcastInstance(config);
HazelcastInstance hz2 = factory.newHazelcastInstance(config);
ClientConfig clientConfig = new ClientConfig();
// ProxyManager#findNextAddressToSendCreateRequest uses the configured load balancer to find the next address
// to which proxy creation request will be sent. We want this to be member hz1.
clientConfig.setLoadBalancer(new StaticLB((Member) hz1.getLocalEndpoint()));
clientConfig.getNetworkConfig().setSmartRouting(false);
// the client only connects to member hz2.
clientConfig.getNetworkConfig().addAddress(hz2.getCluster().getLocalMember().getAddress().getHost() + ":" + hz2.getCluster().getLocalMember().getAddress().getPort());
HazelcastInstance client = factory.newHazelcastClient(clientConfig);
IMap<String, SampleObjects.Employee> test = client.getMap("test");
test.put("foo", new SampleObjects.Employee(1, "name", "age", 32, true, 230));
}
Aggregations