Package com.hazelcast.core

Examples of com.hazelcast.core.HazelcastInstance


  @Test
  public void testMapLockOnStandalone() throws InterruptedException {
    Config cfg = new Config();
    cfg.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);

    HazelcastInstance h1 = Hazelcast.newHazelcastInstance(cfg);
   
    String mapName = new Long (System.nanoTime()).toString();
    String key = "key", anotherKey = "anotherKey";
   
    IMap<String, Integer> map1 = h1.getMap(mapName);
    map1.put(key, 1);
    map1.put(anotherKey, 11);
   
    Thread writeThread1 = new Thread(new RunnableSimpleUpdate<String, Integer>(key, 2, map1));
    Thread writeThread2 = new Thread(new RunnableSimpleUpdate<String, Integer>(anotherKey, 12, map1));
View Full Code Here


  @Test
  public void testPutAll() {
    Config cfg = new Config();
    cfg.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);

    HazelcastInstance h1 = Hazelcast.newHazelcastInstance(cfg);
   
    String mapName = new Long (System.nanoTime()).toString();
    String mapName2 = new Long (System.nanoTime()).toString();
   
    IMap<Integer, String> map1 = h1.getMap(mapName);
    IMap<Integer, String> map2 = h1.getMap(mapName2);

   
    map1.put(1, "un");
    map1.put(2, "deux");
   
View Full Code Here

                    public void entryEvicted(EntryEvent event) {
                        latch.countDown();
                    }
                }));

        final HazelcastInstance instance = Hazelcast.newHazelcastInstance(conf);
        final HTTPCommunicator communicator = new HTTPCommunicator(instance);

        communicator.put(name, "key", "value");
        String value = communicator.get(name, "key");
View Full Code Here

        assertTrue(value.isEmpty());
    }

    @Test
    public void testRestSimple() throws IOException {
        final HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
        final HTTPCommunicator communicator = new HTTPCommunicator(instance);
        final String name = "testRestSimple";
        for (int i = 0; i < 100; i++) {
            assertEquals(HttpURLConnection.HTTP_OK, communicator.put(name, String.valueOf(i), String.valueOf(i * 10)));
        }
View Full Code Here

        }
    }

    @Test
    public void testQueueSizeEmpty() throws IOException {
        final HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
        final HTTPCommunicator communicator = new HTTPCommunicator(instance);
        final String name = "testQueueSizeEmpty";

        IQueue queue = instance.getQueue(name);
        Assert.assertEquals(queue.size(), communicator.size(name));
    }
View Full Code Here

        Assert.assertEquals(queue.size(), communicator.size(name));
    }

    @Test
    public void testQueueSizeNonEmpty() throws IOException {
        final HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
        final HTTPCommunicator communicator = new HTTPCommunicator(instance);
        final String name = "testQueueSizeNotEmpty";
        final int num_items = 100;

        IQueue queue = instance.getQueue(name);

        for (int i = 0; i < num_items; i++) {
            queue.add(i);
        }
View Full Code Here

    }

    @Test(timeout = 120000)
    public void testSemaphoreWithFailuresAndJoin() {
        final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
        final HazelcastInstance instance1 = factory.newHazelcastInstance();
        final HazelcastInstance instance2 = factory.newHazelcastInstance();
        final ISemaphore semaphore = instance1.getSemaphore("test");
        final CountDownLatch countDownLatch = new CountDownLatch(1);

        assertTrue(semaphore.init(0));

        final Thread thread = new Thread() {
            public void run() {
                for (int i = 0; i < 2; i++) {
                    try {
                        semaphore.acquire();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                countDownLatch.countDown();
            }
        };
        thread.start();

        instance2.shutdown();
        semaphore.release();

        HazelcastInstance instance3 = factory.newHazelcastInstance();
        ISemaphore semaphore1 = instance3.getSemaphore("test");
        semaphore1.release();

        try {
            assertTrue(countDownLatch.await(15, TimeUnit.SECONDS));
        } catch (InterruptedException e) {
View Full Code Here

     * is master but node2 thinks node1 is master.
     */
    @Test
    public void testOutOfSyncMemberList() throws Exception {
        List<HazelcastInstance> instanceList = buildInstances(3, 25701);
        final HazelcastInstance h1 = instanceList.get(0);
        final HazelcastInstance h2 = instanceList.get(1);
        final HazelcastInstance h3 = instanceList.get(2);

        // All three nodes join into one cluster
        assertEquals(3, h1.getCluster().getMembers().size());
        assertEquals(3, h2.getCluster().getMembers().size());
        assertEquals(3, h3.getCluster().getMembers().size());

        // This simulates each node reading from the other nodes in the list at regular intervals
        // This prevents the heart beat code from timing out
        final HazelcastInstance[] instances = new HazelcastInstance[]{h1, h2, h3};
        final AtomicBoolean doingWork = new AtomicBoolean(true);
        Thread[] workThreads = new Thread[instances.length];
        for (int i = 0; i < instances.length; i++) {
            final int threadNum = i;
            workThreads[threadNum] = new Thread(new Runnable() {

                public void run() {
                    while (doingWork.get()) {
                        final HazelcastInstance hz = instances[threadNum];

                        Set<Member> members = new HashSet<Member>(hz.getCluster().getMembers());
                        members.remove(hz.getCluster().getLocalMember());

                        final Map<Member, Future<String>> futures = hz.getExecutorService("test")
                                .submitToMembers(new PingCallable(), members);

                        for (Future<String> f : futures.values()) {
                            try {
                                f.get();
View Full Code Here

     * their clusters.
     */
    @Test
    public void testOutOfSyncMemberListTwoMasters() throws Exception {
        List<HazelcastInstance> instanceList = buildInstances(3, 35701);
        final HazelcastInstance h1 = instanceList.get(0);
        final HazelcastInstance h2 = instanceList.get(1);
        final HazelcastInstance h3 = instanceList.get(2);

        final MemberImpl m1 = (MemberImpl) h1.getCluster().getLocalMember();
        final MemberImpl m2 = (MemberImpl) h2.getCluster().getLocalMember();
        final MemberImpl m3 = (MemberImpl) h3.getCluster().getLocalMember();

        // All three nodes join into one cluster
        assertEquals(3, h1.getCluster().getMembers().size());
        assertEquals(3, h2.getCluster().getMembers().size());
        assertEquals(3, h3.getCluster().getMembers().size());

        final Node n2 = TestUtil.getNode(h2);

        // Simulates node2 getting an out of order member list. That causes node2 to think it's the master.
        List<MemberInfo> members = new ArrayList<MemberInfo>();
        members.add(new MemberInfo(m2.getAddress(), m2.getUuid(), Collections. <String, Object> emptyMap()));
        members.add(new MemberInfo(m3.getAddress(), m3.getUuid(), Collections. <String, Object> emptyMap()));
        members.add(new MemberInfo(m1.getAddress(), m1.getUuid(), Collections. <String, Object> emptyMap()));
        n2.clusterService.updateMembers(members);
        n2.setMasterAddress(m2.getAddress());

        // Give the cluster some time to figure things out. The merge and heartbeat code should have kicked in by this point
        Thread.sleep(30 * 1000);

        assertEquals(m1, h1.getCluster().getMembers().iterator().next());
        assertEquals(m1, h2.getCluster().getMembers().iterator().next());
        assertEquals(m1, h3.getCluster().getMembers().iterator().next());

        assertEquals(3, h1.getCluster().getMembers().size());
        assertEquals(3, h2.getCluster().getMembers().size());
        assertEquals(3, h3.getCluster().getMembers().size());
    }
View Full Code Here

    //what are you testing? The intent is not clear
    @Test
    public void testQueueEviction() throws Exception {
        final Config config = new Config();
        config.getQueueConfig("q").setEmptyQueueTtl(2);
        final HazelcastInstance hz = createHazelcastInstance(config);
        final IQueue<Object> q = hz.getQueue("q");

        try {
            assertTrue(q.offer("item"));
            assertEquals("item", q.poll());
            q.take();
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.