Package com.hazelcast.core

Examples of com.hazelcast.core.HazelcastInstance


    public void testDefaultInstance() throws InterruptedException {
        HazelcastServiceFactory factory = new HazelcastServiceFactory();
        factory.init();
        factory.getInstance();
        factory.update(null);
        HazelcastInstance defaultInstance = Hazelcast.newHazelcastInstance(null);

        // define the username and password as in the hazelcast-default.xml provided by Hazelcast
        // without this, "cellar" instance is not in the same cluster as the Hazelcast default one
        Properties properties = new Properties();
        properties.put(HazelcastConfigurationManager.USERNAME, "dev");
        properties.put(HazelcastConfigurationManager.PASSWORD, "dev-pass");
        factory.update(properties);

        HazelcastInstance factoryInstance = factory.getInstance();
        Assert.assertEquals(true, factoryInstance.getCluster().getMembers().size() >= 2);
    }
View Full Code Here


                }
            }
            }

            if (updated) {
                HazelcastInstance instance = lookupInstance();
                if (instance != null) {
                    try {
                        instance.getConfig().setGroupConfig(buildGroupConfig());
                        instance.getConfig().getNetworkConfig().getJoin().setMulticastConfig(buildMulticastConfig());
                        instance.getConfig().getNetworkConfig().getJoin().setTcpIpConfig(buildTcpIpConfig());
                        instance.getLifecycleService().restart();
                    } catch (Exception ex) {
                        logger.error("Error while restarting Hazelcast instance.", ex);
                    }
                }
            }
View Full Code Here

     * Returs a Hazelcast instance from service registry.
     *
     * @return
     */
    public HazelcastInstance lookupInstance() {
        HazelcastInstance instance = null;
        try {
            if (bundleContext != null) {
                ServiceReference reference = bundleContext.getServiceReference("com.hazelcast.core.HazelcastInstance");
                instance = (HazelcastInstance) bundleContext.getService(reference);
                bundleContext.ungetService(reference);
View Full Code Here

        try {
            semaphore.acquire();
        } catch (InterruptedException e) {
            logger.error("Failed to acquire instance semaphore", e);
        }
        HazelcastInstance instance = Hazelcast.newHazelcastInstance(buildConfig());
        return instance;
    }
View Full Code Here

public class RegistryTestCase {

    @Test
    public void test1() throws UnknownHostException {

        HazelcastInstance h1 = create("54327", 9001);

        IMap<Object, Object> h1map = h1.getMap("mymap");
        h1map.put("key1", "bla1");
        Assert.assertEquals("bla1", h1map.get("key1"));

        HazelcastInstance h2 = create("false", 9002, 9001);
        IMap<Object, Object> h2map = h2.getMap("mymap");
        Assert.assertEquals("bla1", h2map.get("key1"));

        HazelcastInstance h3 = create("false", 9003, 9002);
        IMap<Object, Object> h3map = h3.getMap("mymap");
        Assert.assertEquals("bla1", h3map.get("key1"));

        h3map.put("k3", "v3");
        h2map.put("k2", "v2");
       
        Assert.assertEquals("v2", h1map.get("k2"));
        Assert.assertEquals("v3", h1map.get("k3"));
        Assert.assertEquals("v2", h2map.get("k2"));
        Assert.assertEquals("v3", h2map.get("k3"));
        Assert.assertEquals("v2", h3map.get("k2"));
        Assert.assertEquals("v3", h3map.get("k3"));
       
        HazelcastInstance h4 = create("54328", 9004, 9001);
        IMap<Object, Object> h4map = h4.getMap("mymap");
//        Assert.assertNull(h4map.get("k2"));
//        Assert.assertNull(h4map.get("k3"));
        Assert.assertEquals("v2", h4map.get("k2"));
        Assert.assertEquals("v3", h4map.get("k3"));

//        HazelcastInstance h5 = create("false", 9005, 9003, 9004);
        HazelcastInstance h5 = create("54328", 9005);

//        Assert.assertEquals("v2", h4map.get("k2"));
//        Assert.assertEquals("v3", h4map.get("k3"));
       
        IMap<Object, Object> h5map = h5.getMap("mymap");
        Assert.assertEquals("v2", h5map.get("k2"));
        Assert.assertEquals("v3", h5map.get("k3"));
       
        h1.shutdown();
       
View Full Code Here

    public void testRemoveInstance() throws InterruptedException {

        MockEndpoint removed = getMockEndpoint("mock:removed");
        removed.setExpectedMessageCount(1);

        HazelcastInstance h1 = Hazelcast.newHazelcastInstance(null);

        // TODO --> check how an instance can be killed...
        h1.shutdown();

        assertMockEndpointsSatisfied(5000, TimeUnit.MILLISECONDS);

        // check headers
        Exchange ex = removed.getExchanges().get(0);
View Full Code Here

        final Collection<Gauge> gauges = new LinkedList<Gauge>();
        for (final String instance : instances.split(",")) {
            final String trimmed = instance.trim();

            final HazelcastInstance hzInstance;
            final String prefix = Configuration.CONFIG_PROPERTY_PREFIX + "hazelcast." + trimmed + ".";
            if (Configuration.is(prefix + "client", true)) {
                hzInstance = HazelcastClientFactory.newClient(prefix);
            } else {
                hzInstance = HazelcastMemberFactory.newMember(trimmed, prefix);
View Full Code Here

        IoCs.shutdown();
    }

    @Test
    public void gauges() throws Throwable {
        final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance();
        final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance();
        HazelcastInstance instance3 = null;

        Map<Long, Double> members1 = null, partitions;

        final Gauge.LoaderHelper loader = new Gauge.LoaderHelper(false);
        try {
            Thread.sleep(250);
            instance3 = Hazelcast.newHazelcastInstance();
            Thread.sleep(250);

            members1 = gaugeValues("hazelcast-members-cluster");
            partitions = gaugeValues("hazelcast-partitions-cluster");

            Thread.sleep(300);
            assertNotNull(partitions);
            assertEquals(instance2.getPartitionService().getPartitions().size(), partitions.values().iterator().next(), 0.);

            final CountDownLatch instance1Stopped = new CountDownLatch(1);
            instance1.getLifecycleService().addLifecycleListener(new LifecycleListener() {
                @Override
                public void stateChanged(final LifecycleEvent event) {
                    if (LifecycleEvent.LifecycleState.SHUTDOWN.equals(event.getState())) {
                        instance1Stopped.countDown();
                    }
                }
            });
            instance1.getLifecycleService().shutdown();
            instance1Stopped.await();
            Thread.sleep(300);

            assertNotNull(members1);

            assertEquals(2., members1.values().iterator().next(), 0.);
            assertEquals(2., gaugeValues("hazelcast-members-cluster").values().iterator().next(), 0.);
            assertEquals(3., new TreeMap<Long, Double>(members1).lastEntry().getValue(), 0.);
            int tryCount = 0;
            while (true) { // we shouldn't need it but MVN+machine related things can make it fragile if not
                try {
                    assertEquals(2., new TreeMap<Long, Double>(gaugeValues("hazelcast-members-cluster")).lastEntry().getValue(), 0.);
                    break;
                } catch (final Throwable th) {
                    if (tryCount < 10) {
                        tryCount++;
                        Thread.sleep(100);
                    } else {
                        throw th;
                    }
                }
            }
        } finally {
            loader.destroy();
            instance2.getLifecycleService().shutdown();
            if (instance3 != null) {
                instance3.getLifecycleService().shutdown();
            }
            if (instance1.getLifecycleService().isRunning()) {
                instance1.getLifecycleService().shutdown();
            }
        }
View Full Code Here

     * @param name name of the instance in sirona.properties
     * @param prefix could be used to get further config
     * @return the hazelcast instance built from hazelcast.xml + instancename = name
     */
    public static HazelcastInstance newMember(final String name, final String prefix) {
        final HazelcastInstance hazelcastInstanceByName = Hazelcast.getHazelcastInstanceByName(name);
        if (hazelcastInstanceByName != null) {
            return hazelcastInstanceByName;
        }
        return Hazelcast.newHazelcastInstance(new XmlConfigBuilder().build().setInstanceName(name));
    }
View Full Code Here

    private List<String> list;

    @Override
    protected void doPostSetup() throws Exception {
        HazelcastComponent component = context().getComponent("hazelcast", HazelcastComponent.class);
        HazelcastInstance hazelcastInstance = component.getHazelcastInstance();
        list = hazelcastInstance.getList("bar");
        list.clear();
    }
View Full Code Here

TOP

Related Classes of com.hazelcast.core.HazelcastInstance

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.