Package com.hazelcast.core

Examples of com.hazelcast.core.HazelcastInstance


  public void testStandaloneMode() {

    // Start 2 standalone hazelcast instances
    Config cfg = new Config();
    cfg.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
    HazelcastInstance h1 = Hazelcast.newHazelcastInstance(cfg);
    HazelcastInstance h2 = Hazelcast.newHazelcastInstance(cfg);
   
    // Add a new key/value in the 1st instance
    Map<Integer, String> map1 = h1.getMap("testmap");
    map1.put(1, "value 1 on instance 1");

    Map<Integer, String> map2 = h2.getMap("testmap");

    // Check that this key/value was added in the 1st instance and not in the 2nd instance
    assertEquals(1, map1.size());
    assertEquals(0, map2.size());
View Full Code Here


  @Ignore
  public void testClusterMode() {

    // Start 2 clustered hazelcast instances
    HazelcastInstance h1 = Hazelcast.newHazelcastInstance(null);
    HazelcastInstance h2 = Hazelcast.newHazelcastInstance(null);

    // Add a key/value in the 1st instance
    Map<Integer, String> map1 = h1.getMap("testmap");
    map1.put(1, "value 1 on instance 1");

    IMap<Integer, String> map2 = h2.getMap("testmap");
   
    // Check that this key/value was synchronized in the instance 2
    assertEquals(1, map1.size());
    assertEquals(1, map2.size());
View Full Code Here

  @Test
  public void testHazelcastJavaClient() throws UnknownHostException {

    Config cfg = new Config();
    cfg.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
    HazelcastInstance h1 = Hazelcast.newHazelcastInstance(cfg);

    // Connect a client to the cluster
    ClientConfig clientConfig = new ClientConfig() ;
    InetSocketAddress localMemberAddress = h1.getCluster().getLocalMember().getInetSocketAddress();
    clientConfig.addInetSocketAddress(localMemberAddress);
    HazelcastClient client = HazelcastClient.newHazelcastClient(clientConfig);

    // Add a key/value in the cluster using the client
    String mapName = "123";
    IMap<String, String> mapClient = client.getMap(mapName);
    mapClient.put("key1", "value1");

    // Check that the key/value was actually added in the cluster
    IMap<String, String> mapH1 = h1.getMap(mapName);
    mapH1.keySet();
    assertEquals(1, mapH1.size());
    assertEquals("value1", mapH1.get("key1"));
  }
View Full Code Here

    Map <String, MapConfig> mapConfigs = new HashMap<String, MapConfig>();
    mapConfigs.put(mapName, mapConfig);
    config.setMapConfigs(mapConfigs);
   
    // Start a new cluster of Hazelcast isntances
    HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config);

    IMap<String, String> map = h1.getMap(mapName);
    map.put("k1111111111111111111111", "v1");
    map.put("k2222222222222222222222", "v2");
    map.put("k3333333333333333333333", "v3");

    /*
 
View Full Code Here

    MockDataStore.internalStore.put("key1", "value1");
    MockDataStore.internalStore.put("key2", "value2");
    MockDataStore.internalStore.put("key3", "value3");
   
    // Start a new cluster of Hazelcast isntances
    HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config);
   
    IMap<String, String> map = h1.getMap(mapName);
   
    // Check that the map is automatically loaded with the content of the persistent store
    assertEquals(3, map.size());
    assertEquals("value1", map.get("key1"));
   
View Full Code Here

//    Map <String, MapConfig> mapConfigs = new HashMap<String, MapConfig>();
//    mapConfigs.put(mapName, mapConfig);
//    config.setMapConfigs(mapConfigs);
    config.getMapConfig(mapName).setNearCacheConfig(nearCacheConfig);
   
    HazelcastInstance hOnGtw1 = Hazelcast.newHazelcastInstance(config);
    HazelcastInstance hOnGtw2 = Hazelcast.newHazelcastInstance(config);

//    hOnGtw1.getConfig().getMapConfigs()
//    hOnGtw1.getConfig().getMapConfig(mapName).getNearCacheConfig()
//    hOnGtw2.getConfig().getMapConfig(mapName).getNearCacheConfig()
//   
//    hOnGtw1.getConfig().getMapConfig(mapName).
   
   
    IMap<String, String> apisMapOnG1 = hOnGtw1.getMap(mapName);
   
    apisMapOnG1.put("api1", "api1Policies");
    apisMapOnG1.put("api2", "api2Policies");
//    assertEquals(2, apisMapOnG1.localKeySet().size());
   
    // Check that "apisMap" is replicated on gtw2
    IMap<String, String> apisMapOnG2 = hOnGtw2.getMap(mapName);

    assertEquals(2, apisMapOnG2.size());
    assertEquals(2, apisMapOnG2.localKeySet().size());
   
    // Check that "apisMap" creation and updates are replicated on gtw1
View Full Code Here

    nearCacheConfig.setMaxSize(10000);
   
    Config config = new Config();
    config.getMapConfig(mapName).setNearCacheConfig(nearCacheConfig);
   
    HazelcastInstance hOnGtw1 = Hazelcast.newHazelcastInstance(config);
    HazelcastInstance hOnGtw2 = Hazelcast.newHazelcastInstance(config);

    IMap<String, String> apisMapOnG1 = hOnGtw1.getMap(mapName);
   
    apisMapOnG1.put("api1", "api1Policies");
    apisMapOnG1.put("api2", "api2Policies");
    assertEquals(2, apisMapOnG1.localKeySet().size());
   
    // Check that "apisMap" is replicated on gtw2
    IMap<String, String> apisMapOnG2 = hOnGtw2.getMap(mapName);

    assertEquals(2, apisMapOnG2.size());
    assertEquals(2, apisMapOnG2.localKeySet().size());
   
    // Check that "apisMap" creation and updates are replicated on gtw1
View Full Code Here

    nearCacheConfig.setMaxSize(10000);
   
    Config config = new Config();
    config.getMapConfig(mapName).setNearCacheConfig(nearCacheConfig);
   
    HazelcastInstance hOnGtw1 = Hazelcast.newHazelcastInstance(config);
   
    IMap<String, String> apisMapOnG1 = hOnGtw1.getMap(mapName);
   
    apisMapOnG1.put("api1", "api1Policies");
    apisMapOnG1.put("api2", "api2Policies");

    assertEquals("api1Policies", apisMapOnG1.get("api1"));
View Full Code Here

    config.getMapConfig(mapName).setReadBackupData(true);
   
//    config.getNetworkConfig().getSocketInterceptorConfig().
 
   
    HazelcastInstance hOnGtw1 = Hazelcast.newHazelcastInstance(config);
    assertEquals(20, hOnGtw1.getConfig().getMapConfig(mapName).getBackupCount());
   
//    HazelcastInstance hOnGtw2 = Hazelcast.newHazelcastInstance(config);
//    assertEquals(2, hOnGtw2.getConfig().getMapConfig(mapName).getBackupCount());
   
    IMap<String, String> apisMapOnG1 = hOnGtw1.getMap(mapName);
    // Check that "apisMap" is replicated on gtw2
//    IMap<String, String> apisMapOnG2 = hOnGtw2.getMap(mapName);

    apisMapOnG1.put("api10", "api1Policies");
//    apisMapOnG1.put("api2", "api2Policies");
View Full Code Here

  @Test
  public void testLockOnStandalone() 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

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.