Search in sources :

Example 16 with XmlConfigBuilder

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);
}
Also used : XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) InputStream(java.io.InputStream) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 17 with XmlConfigBuilder

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.");
    }
}
Also used : XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) MapStoreConfig(com.hazelcast.config.MapStoreConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) CountDownLatch(java.util.concurrent.CountDownLatch) IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 18 with XmlConfigBuilder

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();
    }
}
Also used : XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) MapStoreConfig(com.hazelcast.config.MapStoreConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) CountDownLatch(java.util.concurrent.CountDownLatch) IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) MapConfig(com.hazelcast.config.MapConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 19 with XmlConfigBuilder

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"));
}
Also used : MapStoreWrapper(com.hazelcast.map.impl.MapStoreWrapper) XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) HazelcastInstance(com.hazelcast.core.HazelcastInstance) InputStream(java.io.InputStream) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) GroupConfig(com.hazelcast.config.GroupConfig) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) Iterator(java.util.Iterator) MapService(com.hazelcast.map.impl.MapService) MapContainer(com.hazelcast.map.impl.MapContainer) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 20 with XmlConfigBuilder

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));
}
Also used : XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) MapIndexConfig(com.hazelcast.config.MapIndexConfig) SampleObjects(com.hazelcast.query.SampleObjects) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) MapConfig(com.hazelcast.config.MapConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) StaticLB(com.hazelcast.client.util.StaticLB) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

XmlConfigBuilder (com.hazelcast.config.XmlConfigBuilder)25 Config (com.hazelcast.config.Config)20 Test (org.junit.Test)10 InputStream (java.io.InputStream)9 QuickTest (com.hazelcast.test.annotation.QuickTest)8 MapConfig (com.hazelcast.config.MapConfig)7 JoinConfig (com.hazelcast.config.JoinConfig)6 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 URL (java.net.URL)6 MapStoreConfig (com.hazelcast.config.MapStoreConfig)5 MulticastConfig (com.hazelcast.config.MulticastConfig)5 TcpIpConfig (com.hazelcast.config.TcpIpConfig)5 AwsConfig (com.hazelcast.config.AwsConfig)4 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)4 DiscoveryStrategyConfig (com.hazelcast.config.DiscoveryStrategyConfig)4 InterfacesConfig (com.hazelcast.config.InterfacesConfig)4 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)3 ParallelTest (com.hazelcast.test.annotation.ParallelTest)3 ClientConfig (com.hazelcast.client.config.ClientConfig)2 CacheSimpleConfig (com.hazelcast.config.CacheSimpleConfig)2