public static void main(String[] args) { Config cfg = new Config(); HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg); Map<Integer, String> mapCustomers = instance.getMap("customers"); mapCustomers.put(1, "Joe"); mapCustomers.put(2, "Ali"); mapCustomers.put(3, "Avi"); System.out.println("Customer with key 1: "+ mapCustomers.get(1)); System.out.println("Map Size:" + mapCustomers.size()); Queue<String> queueCustomers = instance.getQueue("customers"); queueCustomers.offer("Tom"); queueCustomers.offer("Mary"); queueCustomers.offer("Jane"); System.out.println("First customer: " + queueCustomers.poll()); System.out.println("Second customer: "+ queueCustomers.peek()); System.out.println("Queue size: " + queueCustomers.size()); }
@Bean(TENANT_CONFIGURATION_HAZELCAST) public HazelcastInstance tenantConfigurationHazelcast() throws IOException { log.info("{}", appProps.getHazelcast()); Properties props = new Properties(); props.putAll(appProps.getHazelcast()); props.put(HAZELCAST_LOCAL_LOCAL_ADDRESS, InetUtils.getFirstNonLoopbackHostInfo().getIpAddress()); String hazelcastConfigUrl = appProps.getHazelcast().get(HAZELCAST_CONFIG_URL_PROPERTY); InputStream in = context.getResource(hazelcastConfigUrl).getInputStream(); Config config = new XmlConfigBuilder(in).setProperties(props).build(); config.getNetworkConfig().setInterfaces(buildInterfaces(appProps.getHazelcast().get(INTERFACES))); HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config); return hazelcastInstance; }
@Bean public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) { log.debug("Configuring Hazelcast"); HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName("balance"); if (hazelCastInstance != null) { log.debug("Hazelcast already initialized"); return hazelCastInstance; } Config config = new Config(); config.setInstanceName("balance"); config.getNetworkConfig().setPort(5701); config.getNetworkConfig().setPortAutoIncrement(true); // In development, remove multicast auto-configuration if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { System.setProperty("hazelcast.local.localAddress", "127.0.0.1"); config.getNetworkConfig().getJoin().getAwsConfig().setEnabled(false); config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false); config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(false); } config.getMapConfigs().put("default", initializeDefaultMapConfig()); config.getMapConfigs().put("com.icthh.xm.ms.balance.domain.*", initializeDomainMapConfig(jHipsterProperties)); return Hazelcast.newHazelcastInstance(config); }
/** * Hazelcast instance that is used by the spring session * repository to broadcast session events. The name * of this bean must be left untouched. * * @return the hazelcast instance */ @Bean public HazelcastInstance hazelcastInstance() { final Resource hzConfigResource = casProperties.getWebflow().getSession().getHzLocation(); try { final URL configUrl = hzConfigResource.getURL(); final Config config = new XmlConfigBuilder(hzConfigResource.getInputStream()).build(); config.setConfigurationUrl(configUrl); config.setInstanceName(this.getClass().getSimpleName()) .setProperty("hazelcast.logging.type", "slf4j") .setProperty("hazelcast.max.no.heartbeat.seconds", "300"); return Hazelcast.newHazelcastInstance(config); } catch (final Exception e) { throw Throwables.propagate(e); } }
@Bean @Primary public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) { log.debug("Configuring Hazelcast"); HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName("dashboard"); if (hazelCastInstance != null) { log.debug("Hazelcast already initialized"); return hazelCastInstance; } Config config = new Config(); config.setInstanceName("dashboard"); config.getNetworkConfig().setPort(5701); config.getNetworkConfig().setPortAutoIncrement(true); // In development, remove multicast auto-configuration if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { System.setProperty("hazelcast.local.localAddress", "127.0.0.1"); config.getNetworkConfig().getJoin().getAwsConfig().setEnabled(false); config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false); config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(false); } config.getMapConfigs().put("default", initializeDefaultMapConfig()); config.getMapConfigs().put("com.icthh.xm.ms.dashboard.domain.*", initializeDomainMapConfig(jHipsterProperties)); return Hazelcast.newHazelcastInstance(config); }
@Bean @Primary public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) { log.debug("Configuring Hazelcast"); HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName("gate"); if (hazelCastInstance != null) { log.debug("Hazelcast already initialized"); return hazelCastInstance; } Config config = new Config(); config.setInstanceName("gate"); config.getNetworkConfig().setPort(5701); config.getNetworkConfig().setPortAutoIncrement(true); // In development, remove multicast auto-configuration if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { System.setProperty("hazelcast.local.localAddress", "127.0.0.1"); config.getNetworkConfig().getJoin().getAwsConfig().setEnabled(false); config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false); config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(false); } config.getMapConfigs().put("default", initializeDefaultMapConfig()); config.getMapConfigs().put("com.icthh.xm.gate.domain.*", initializeDomainMapConfig(jHipsterProperties)); return Hazelcast.newHazelcastInstance(config); }
@Bean @Primary public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) { log.debug("Configuring Hazelcast"); HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName("entity"); if (hazelCastInstance != null) { log.debug("Hazelcast already initialized"); return hazelCastInstance; } Config config = new Config(); config.setInstanceName("entity"); config.getNetworkConfig().setPort(5701); config.getNetworkConfig().setPortAutoIncrement(true); // In development, remove multicast auto-configuration if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { System.setProperty("hazelcast.local.localAddress", "127.0.0.1"); config.getNetworkConfig().getJoin().getAwsConfig().setEnabled(false); config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false); config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(false); } config.getMapConfigs().put("default", initializeDefaultMapConfig()); config.getMapConfigs().put("com.icthh.xm.ms.entity.domain.*", initializeDomainMapConfig(jHipsterProperties)); return Hazelcast.newHazelcastInstance(config); }
@Bean public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) { log.debug("Configuring Hazelcast"); Config config = new Config(); config.setInstanceName("operoncloudplatform"); config.getNetworkConfig().setPort(5701); config.getNetworkConfig().setPortAutoIncrement(true); // In development, remove multicast auto-configuration if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { System.setProperty("hazelcast.local.localAddress", "127.0.0.1"); config.getNetworkConfig().getJoin().getAwsConfig().setEnabled(false); config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false); config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(false); } config.getMapConfigs().put("default", initializeDefaultMapConfig()); config.getMapConfigs().put("cloud.operon.platform.domain.*", initializeDomainMapConfig(jHipsterProperties)); return Hazelcast.newHazelcastInstance(config); }
/** * Main method for executing the schema conversion to Hazelcast. * The method just needs to be called statically as it operates on files created during the initial * schema conversion process. */ public static void executeSchemaChange() { Config cfg = new Config(); HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg); mapNodes = instance.getMap("nodes"); mapEdges = instance.getMap("edges"); mapLabels = instance.getMap("labels"); mapOut = instance.getMap("out"); mapIn = instance.getMap("in"); nodesMap(); edgesMap(); exampleQueries(); }
@PostConstruct public void init() { Config config = this.hazelcastInstance.getConfig(); String mapName = this.sessionProperties.getMapName(); MapConfig mapConfig = config.getMapConfigOrNull(mapName); if (mapConfig == null) { // @formatter:off MapAttributeConfig principalNameAttributeConfig = new MapAttributeConfig() .setName(HazelcastSessionRepository.PRINCIPAL_NAME_ATTRIBUTE) .setExtractor(PrincipalNameExtractor.class.getName()); // @formatter:on MapIndexConfig principalNameIndexConfig = new MapIndexConfig( HazelcastSessionRepository.PRINCIPAL_NAME_ATTRIBUTE, false); // @formatter:off mapConfig = new MapConfig(mapName) .addMapAttributeConfig(principalNameAttributeConfig) .addMapIndexConfig(principalNameIndexConfig); // @formatter:on config.addMapConfig(mapConfig); } }
@Test public void testIntegration() { String zookeeperURL = zkTestServer.getConnectString(); Config config = new Config(); config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false); config.setProperty("hazelcast.discovery.enabled", "true"); DiscoveryStrategyConfig discoveryStrategyConfig = new DiscoveryStrategyConfig(new ZookeeperDiscoveryStrategyFactory()); discoveryStrategyConfig.addProperty(ZookeeperDiscoveryProperties.ZOOKEEPER_URL.key(), zookeeperURL); config.getNetworkConfig().getJoin().getDiscoveryConfig().addDiscoveryStrategyConfig(discoveryStrategyConfig); HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config); HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(config); int instance1Size = instance1.getCluster().getMembers().size(); assertEquals(2, instance1Size); int instance2Size = instance2.getCluster().getMembers().size(); assertEquals(2, instance2Size); }
/** * Add configuration to the supplied {@link Config} to support the use of a {@link HazelcastCommandExecutor}. * @param config The {@link Config} to configure. * @return The updated {@link Config}. */ public Config addCommandExecutorConfiguration(Config config) { SerializerConfig serializerConfig = new SerializerConfig() .setImplementation(RemoteCommandSerialiser.using( objectMapper, CommandTypeMatcher.matchingAgainst(typeInfoMap))) .setTypeClass(RemoteCommand.class); ManagedContext managedContext = CommandProcessingManagedContext .processingCommandsWith(dispatchingCommandProcessor); config.getSerializationConfig().addSerializerConfig(serializerConfig); config.setManagedContext(config.getManagedContext() == null ? managedContext : CompositeManagedContext.of(managedContext, config.getManagedContext())); config.addExecutorConfig(new ExecutorConfig(executorName, threadsPerNode)); return config; }
public static void main(String[] args) { try { // 获取配置文件磁盘路径 final String path = Thread.currentThread().getContextClassLoader().getResource("").toString() + DEF_CONFIG_FILE; // 构建XML配置 XmlConfigBuilder builder = new XmlConfigBuilder(path); // 配置对应的properties解析参数 builder.setProperties(getProperties()); // 创建Config Config config = builder.build(); // 输出Config参数 System.out.println(config.getGroupConfig().getName()); } catch (FileNotFoundException e) { e.printStackTrace(); } }
public static void main(String[] args) { // 创建默认config对象 Config config = new Config(); // 获取network元素<network></network> NetworkConfig netConfig = config.getNetworkConfig(); System.out.println("Default port:" + netConfig.getPort()); // 设置组网起始监听端口 netConfig.setPort(9701); System.out.println("Customer port:" + netConfig.getPort()); // 获取join元素<join></join> JoinConfig joinConfig = netConfig.getJoin(); // 获取multicast元素<multicast></multicast> MulticastConfig multicastConfig = joinConfig.getMulticastConfig(); // 输出组播协议端口 System.out.println(multicastConfig.getMulticastPort()); // 禁用multicast协议 multicastConfig.setEnabled(false); // 初始化Hazelcast Hazelcast.newHazelcastInstance(config); }
@Bean public Config hazelcastConfig () { val config = new Config(); config.setProperty("hazelcast.discovery.enabled", "true"); val networkingConfig = config.getNetworkConfig(); networkingConfig.setPort(hazelcastPort); networkingConfig.setPortAutoIncrement(false); val joinConfig = networkingConfig.getJoin(); joinConfig.getMulticastConfig().setEnabled(false); joinConfig.getTcpIpConfig().setEnabled(false); joinConfig.getAwsConfig().setEnabled(false); joinConfig.getDiscoveryConfig() .addDiscoveryStrategyConfig(new DiscoveryStrategyConfig(discoveryStrategyFactory())); return config; }
@Test public void testNamedInstance() { TestHazelcastFactory factory = new TestHazelcastFactory(); Config config = new Config(); config.setInstanceName("hibernate"); HazelcastInstance hz = factory.newHazelcastInstance(config); Properties props = new Properties(); props.setProperty(Environment.CACHE_REGION_FACTORY, HazelcastCacheRegionFactory.class.getName()); props.put(CacheEnvironment.HAZELCAST_INSTANCE_NAME, "hibernate"); props.put(CacheEnvironment.SHUTDOWN_ON_STOP, "false"); props.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect"); Configuration configuration = new Configuration(); configuration.addProperties(props); SessionFactory sf = configuration.buildSessionFactory(); assertTrue(hz.equals(HazelcastAccessor.getHazelcastInstance(sf))); sf.close(); assertTrue(hz.getLifecycleService().isRunning()); factory.shutdownAll(); }
@Test public void testExternalRegistration(){ EurekaHttpResponse<Applications> response = generateMockResponse(Collections.<InstanceInfo>emptyList()); when(requestHandler.getApplications()).thenReturn(response); Config config = new XmlConfigBuilder().build(); DiscoveryConfig discoveryConfig = config.getNetworkConfig().getJoin().getDiscoveryConfig(); DiscoveryStrategyConfig strategyConfig = discoveryConfig.getDiscoveryStrategyConfigs().iterator().next(); strategyConfig.addProperty("self-registration", "false"); HazelcastInstance hz1 = factory.newHazelcastInstance(config); HazelcastInstance hz2 = factory.newHazelcastInstance(config); assertClusterSizeEventually(2, hz1); assertClusterSizeEventually(2, hz2); verify(requestHandler, after(5000).never()).register(any(InstanceInfo.class)); }
@Test public void discoveryStrategyFactoryTest() { JCloudsDiscoveryStrategyFactory jCloudsDiscoveryStrategyFactory = new JCloudsDiscoveryStrategyFactory(); String xmlFileName = "test-jclouds-config.xml"; InputStream xmlResource = JCloudsDiscoveryFactoryTest.class.getClassLoader().getResourceAsStream(xmlFileName); Config config = new XmlConfigBuilder(xmlResource).build(); JoinConfig joinConfig = config.getNetworkConfig().getJoin(); DiscoveryConfig discoveryConfig = joinConfig.getDiscoveryConfig(); DiscoveryStrategyConfig providerConfig = discoveryConfig.getDiscoveryStrategyConfigs().iterator().next(); assertEquals(jCloudsDiscoveryStrategyFactory.getDiscoveryStrategyType(), JCloudsDiscoveryStrategy.class); assertEquals(JCloudsDiscoveryStrategy.class.getName(), providerConfig.getClassName()); assertEquals(jCloudsDiscoveryStrategyFactory.getConfigurationProperties().size(), providerConfig.getProperties().size()); assertTrue(jCloudsDiscoveryStrategyFactory. newDiscoveryStrategy(null, null, new HashMap<String, Comparable>()) instanceof DiscoveryStrategy); }
private Config createConfig() { Config config; try { config = new XmlConfigBuilder(Application.class.getClassLoader().getResource(CONFIG_NAME)).build(); } catch (IOException e) { logger.error(e.getMessage(), e); throw new Error(e); } config.getSerializationConfig().addDataSerializableFactory(SerializableFactory.ID, new SerializableFactory()); config.getSerializationConfig().getSerializerConfigs().add(new SerializerConfig().setTypeClass(JsonNode.class) .setImplementation(JsonSerializer.makePlain(JsonNode.class))); return config; }
@Test public void configInstanceWithName() { Config config = new Config("my-test-instance"); HazelcastInstance existingHazelcastInstance = Hazelcast .newHazelcastInstance(config); try { load(HazelcastConfigWithName.class, "spring.hazelcast.config=this-is-ignored.xml"); HazelcastInstance hazelcastInstance = this.context .getBean(HazelcastInstance.class); assertThat(hazelcastInstance.getConfig().getInstanceName()) .isEqualTo("my-test-instance"); // Should reuse any existing instance by default. assertThat(hazelcastInstance).isEqualTo(existingHazelcastInstance); } finally { existingHazelcastInstance.shutdown(); } }
/** * * @throws FileNotFoundException * @throws ConfigurationException */ private HazelcastInstanceProxy(Config hzConfig, String entityScanPath) { this.hzConfig = hzConfig; setProperty("hazelcast.event.thread.count", "6"); setProperty("hazelcast.operation.thread.count", "4"); setProperty("hazelcast.io.thread.count", "4"); //4+4+1 setProperty("hazelcast.shutdownhook.enabled", "false"); try { addMapConfigs(EntityFinder.findMapEntityClasses(entityScanPath)); } catch (Exception e) { throw new BeanCreationException("Unable to load entity classes", e); } }
@Test public void testGlobalCustomSerializationConfiguredProgrammaticallyForClientConfig() { Config memberConfig = new Config(); SubZero.useAsGlobalSerializer(memberConfig); hazelcastFactory.newHazelcastInstance(memberConfig); String mapName = randomMapName(); ClientConfig config = new ClientConfig(); SubZero.useAsGlobalSerializer(config, MyGlobalUserSerlizationConfig.class); HazelcastInstance member = hazelcastFactory.newHazelcastClient(config); IMap<Integer, AnotherNonSerializableObject> myMap = member.getMap(mapName); myMap.put(0, new AnotherNonSerializableObject()); AnotherNonSerializableObject fromCache = myMap.get(0); assertEquals("deserialized", fromCache.name); }
@Test public void testGlobalCustomDelegateSerializationConfiguredProgrammaticallyForClientConfig() { Config memberConfig = new Config(); SubZero.useAsGlobalSerializer(memberConfig); hazelcastFactory.newHazelcastInstance(memberConfig); String mapName = randomMapName(); ClientConfig config = new ClientConfig(); SubZero.useAsGlobalSerializer(config, MyGlobalDelegateSerlizationConfig.class); HazelcastInstance member = hazelcastFactory.newHazelcastClient(config); IMap<Integer, AnotherNonSerializableObject> myMap = member.getMap(mapName); myMap.put(0, new AnotherNonSerializableObject()); AnotherNonSerializableObject fromCache = myMap.get(0); assertEquals("deserialized", fromCache.name); }
@Test public void testTypedCustomSerializer_configuredBySubclassing() throws Exception { String mapName = randomMapName(); Config config = new Config(); SerializerConfig serializerConfig = new SerializerConfig(); serializerConfig.setClass(MySerializer.class); serializerConfig.setTypeClass(AnotherNonSerializableObject.class); config.getSerializationConfig().getSerializerConfigs().add(serializerConfig); HazelcastInstance member = hazelcastFactory.newHazelcastInstance(config); IMap<Integer, AnotherNonSerializableObject> myMap = member.getMap(mapName); myMap.put(0, new AnotherNonSerializableObject()); AnotherNonSerializableObject fromCache = myMap.get(0); assertEquals("deserialized", fromCache.name); }
@Override protected void doStart() throws Exception { if (maximumRedeliveries < 0) { throw new IllegalArgumentException("Maximum redelivery retries must be zero or a positive integer."); } if (recoveryInterval < 0) { throw new IllegalArgumentException("Recovery interval must be zero or a positive integer."); } ObjectHelper.notEmpty(mapName, "repositoryName"); if (useLocalHzInstance) { Config cfg = new XmlConfigBuilder().build(); cfg.setProperty("hazelcast.version.check.enabled", "false"); hzInstance = Hazelcast.newHazelcastInstance(cfg); } else { ObjectHelper.notNull(hzInstance, "hzInstanse"); } cache = hzInstance.getMap(mapName); if (useRecovery) { persistedCache = hzInstance.getMap(persistenceMapName); } }
@Before public void setUp() throws Exception { mapConfig = mock(MapConfig.class); when(mapConfig.getMaxSizeConfig()).thenReturn(new MaxSizeConfig(maxSize, MaxSizeConfig.MaxSizePolicy.PER_NODE)); when(mapConfig.getTimeToLiveSeconds()).thenReturn(timeout); config = mock(Config.class); when(config.findMapConfig(eq(REGION_NAME))).thenReturn(mapConfig); Cluster cluster = mock(Cluster.class); when(cluster.getClusterTime()).thenAnswer(new Answer<Long>() { @Override public Long answer(InvocationOnMock invocation) throws Throwable { return System.currentTimeMillis(); } }); instance = mock(HazelcastInstance.class); when(instance.getConfig()).thenReturn(config); when(instance.getCluster()).thenReturn(cluster); region = new HazelcastQueryResultsRegion(instance, REGION_NAME, new Properties()); }
/** * Create hazelcast full instance. * * @param configLocation the config location * @return the hazelcast instance */ public static HazelcastInstance createHazelcastFullInstance(String configLocation) { Config config; try { if (configLocation == null) { config = new XmlConfigBuilder().build(); } else { config = ConfigLoader.load(configLocation); } } catch (IOException e) { throw new RuntimeException("failed to load config", e); } checkNotNull(config, "failed to find configLocation: " + configLocation); config.setInstanceName(DEFAULT_INSTANCE_NAME); return Hazelcast.getOrCreateHazelcastInstance(config); }
@Before public void setUp() throws Exception { mapConfig = mock(MapConfig.class); when(mapConfig.getMaxSizeConfig()).thenReturn(new MaxSizeConfig(50, MaxSizeConfig.MaxSizePolicy.PER_NODE)); when(mapConfig.getTimeToLiveSeconds()).thenReturn(timeout); config = mock(Config.class); when(config.findMapConfig(eq(REGION_NAME))).thenReturn(mapConfig); Cluster cluster = mock(Cluster.class); when(cluster.getClusterTime()).thenAnswer(new Answer<Long>() { @Override public Long answer(InvocationOnMock invocation) throws Throwable { return System.currentTimeMillis(); } }); instance = mock(HazelcastInstance.class); when(instance.getConfig()).thenReturn(config); when(instance.getCluster()).thenReturn(cluster); cache = mock(RegionCache.class); region = new HazelcastTimestampsRegion<RegionCache>(instance, REGION_NAME, new Properties(), cache); }
@Test public void testThreeArgConstructorRegistersTopicListener() { MapConfig mapConfig = mock(MapConfig.class); Config config = mock(Config.class); when(config.findMapConfig(eq(CACHE_NAME))).thenReturn(mapConfig); ITopic<Object> topic = mock(ITopic.class); when(topic.addMessageListener(isNotNull(MessageListener.class))).thenReturn("ignored"); HazelcastInstance instance = mock(HazelcastInstance.class); when(instance.getConfig()).thenReturn(config); when(instance.getTopic(eq(CACHE_NAME))).thenReturn(topic); new LocalRegionCache(CACHE_NAME, instance, null); verify(config).findMapConfig(eq(CACHE_NAME)); verify(instance).getConfig(); verify(instance).getTopic(eq(CACHE_NAME)); verify(topic).addMessageListener(isNotNull(MessageListener.class)); }
@Bean public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) { log.debug("Configuring Hazelcast"); HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName("uaa"); if (hazelCastInstance != null) { log.debug("Hazelcast already initialized"); return hazelCastInstance; } Config config = new Config(); config.setInstanceName("uaa"); config.getNetworkConfig().setPort(5701); config.getNetworkConfig().setPortAutoIncrement(true); // In development, remove multicast auto-configuration if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) { System.setProperty("hazelcast.local.localAddress", "127.0.0.1"); config.getNetworkConfig().getJoin().getAwsConfig().setEnabled(false); config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false); config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(false); } config.getMapConfigs().put("default", initializeDefaultMapConfig()); config.getMapConfigs().put("com.icthh.xm.uaa.domain.*", initializeDomainMapConfig(jHipsterProperties)); // Uncomment if session needed //config.getMapConfigs().put("clustered-http-sessions", initializeClusteredSession(jHipsterProperties)); return Hazelcast.newHazelcastInstance(config); }
@Bean public Config hazelCastConfig() { Config config = new Config(); config.setInstanceName("hazelcast-packt-cache"); config.setProperty("hazelcast.jmx", "true"); MapConfig deptCache = new MapConfig(); deptCache.setTimeToLiveSeconds(20); deptCache.setEvictionPolicy(EvictionPolicy.LFU); config.getMapConfigs().put("hazeldept",deptCache); return config; }
@Test public void correctHazelcastInstanceIsCreated() throws Exception { assertNotNull(this.hzInstance); final Config config = this.hzInstance.getConfig(); assertFalse(config.getNetworkConfig().getJoin().getMulticastConfig().isEnabled()); assertEquals(Arrays.asList("localhost"), config.getNetworkConfig().getJoin().getTcpIpConfig().getMembers()); assertTrue(config.getNetworkConfig().isPortAutoIncrement()); assertEquals(5701, config.getNetworkConfig().getPort()); final MapConfig mapConfig = config.getMapConfig("tickets"); assertNotNull(mapConfig); assertEquals(28800, mapConfig.getMaxIdleSeconds()); assertEquals(EvictionPolicy.LRU, mapConfig.getEvictionPolicy()); assertEquals(10, mapConfig.getEvictionPercentage()); }
@Test public void hazelcastInstanceIsCreatedNormally() throws Exception { assertNotNull(this.hzInstance); final Config config = this.hzInstance.getConfig(); assertTrue(config.getNetworkConfig().getJoin().getMulticastConfig().isEnabled()); assertEquals(Arrays.asList("127.0.0.1"), config.getNetworkConfig().getJoin().getTcpIpConfig().getMembers()); assertFalse(config.getNetworkConfig().isPortAutoIncrement()); assertEquals(5801, config.getNetworkConfig().getPort()); final MapConfig mapConfig = config.getMapConfig("tickets-from-external-config"); assertNotNull(mapConfig); assertEquals(20000, mapConfig.getMaxIdleSeconds()); assertEquals(EvictionPolicy.LFU, mapConfig.getEvictionPolicy()); assertEquals(99, mapConfig.getEvictionPercentage()); }
@Test public void correctHazelcastInstanceIsCreated() throws Exception { assertNotNull(this.hzInstance); final Config config = this.hzInstance.getConfig(); assertFalse(config.getNetworkConfig().getJoin().getMulticastConfig().isEnabled()); assertEquals(Arrays.asList("localhost"), config.getNetworkConfig().getJoin().getTcpIpConfig().getMembers()); assertTrue(config.getNetworkConfig().isPortAutoIncrement()); assertEquals(5701, config.getNetworkConfig().getPort()); assertEquals(2, config.getMapConfigs().size()); }