def init(): logging.basicConfig( format='%(asctime)s%(msecs)03d [%(name)s] %(levelname)s: %(message)s', datefmt="%H:%M%:%S,") logging.getLogger().setLevel(logging.INFO) logger = logging.getLogger("main") config = hazelcast.ClientConfig() config.group_config.name = "dev" config.group_config.password = "******" config.network_config.addresses.append("127.0.0.1:5701") near_cache_config = NearCacheConfig(MAP_NAME) near_cache_config.in_memory_format = IN_MEMORY_FORMAT.OBJECT config.add_near_cache_config(near_cache_config) client = hazelcast.HazelcastClient(config) my_map = client.get_map(MAP_NAME).blocking() print "START INIT" for key in xrange(0, ENTRY_COUNT): my_map.put(key, VALUE) for key in xrange(0, ENTRY_COUNT): my_map.get(key) print "INIT COMPLETE" return my_map
def init(): logging.basicConfig(format='%(asctime)s%(msecs)03d [%(name)s] %(levelname)s: %(message)s', datefmt="%H:%M%:%S,") logging.getLogger().setLevel(logging.INFO) logger = logging.getLogger("main") config = hazelcast.ClientConfig() config.group_config.name = "dev" config.group_config.password = "******" config.network_config.addresses.append("127.0.0.1:5701") near_cache_config = NearCacheConfig(MAP_NAME) near_cache_config.in_memory_format = IN_MEMORY_FORMAT.OBJECT config.add_near_cache_config(near_cache_config) client = hazelcast.HazelcastClient(config) my_map = client.get_map(MAP_NAME).blocking() print "START INIT" for key in xrange(0, ENTRY_COUNT): my_map.put(key, VALUE) for key in xrange(0, ENTRY_COUNT): my_map.get(key) print "INIT COMPLETE" return my_map
def configure_client(cls, config): config.cluster_name = cls.cluster.id near_cache_config = NearCacheConfig(random_string()) # near_cache_config.time_to_live_seconds = 1000 # near_cache_config.max_idle_seconds = 1000 config.add_near_cache_config(near_cache_config) return super(MapTest, cls).configure_client(config)
def init(): logging.basicConfig( format='%(asctime)s%(msecs)03d [%(name)s] %(levelname)s: %(message)s', datefmt="%H:%M%:%S,") logging.getLogger().setLevel(logging.INFO) logger = logging.getLogger("main") config = hazelcast.ClientConfig() config.group_config.name = "dev" config.group_config.password = "******" config.network_config.addresses.append("127.0.0.1") near_cache_config = NearCacheConfig(MAP_NAME) near_cache_config.in_memory_format = IN_MEMORY_FORMAT.OBJECT config.add_near_cache_config(near_cache_config) try: from hzrc.client import HzRemoteController rc = HzRemoteController('127.0.0.1', '9701') if not rc.ping(): logger.info("Remote Controller Server not running... exiting.") exit() logger.info("Remote Controller Server OK...") rc_cluster = rc.createCluster(None, None) rc_member = rc.startMember(rc_cluster.id) config.network_config.addresses.append('{}:{}'.format( rc_member.host, rc_member.port)) except (ImportError, NameError): config.network_config.addresses.append('127.0.0.1') client = hazelcast.HazelcastClient(config) my_map = client.get_map(MAP_NAME).blocking() print "START INIT" for key in xrange(0, ENTRY_COUNT): my_map.put(key, VALUE) for key in xrange(0, ENTRY_COUNT): my_map.get(key) print "INIT COMPLETE" return my_map
def test_near_cache_stats(self): config = ClientConfig() config.set_property(ClientProperties.STATISTICS_ENABLED.name, True) config.set_property(ClientProperties.STATISTICS_PERIOD_SECONDS.name, self.STATS_PERIOD) map_name = random_string() near_cache_config = NearCacheConfig(map_name) config.near_cache_configs[map_name] = near_cache_config client = HazelcastClient(config) client_uuid = client.cluster.uuid test_map = client.get_map(map_name).blocking() time.sleep(2 * self.STATS_PERIOD) response = self._wait_for_statistics_collection(client_uuid) result = response.result.decode("utf-8") self.assertEqual(1, result.count("nc." + map_name + ".evictions=0")) self.assertEqual(1, result.count("nc." + map_name + ".hits=0")) self.assertEqual(1, result.count("nc." + map_name + ".misses=0")) self.assertEqual(1, result.count("nc." + map_name + ".ownedEntryCount=0")) self.assertEqual(1, result.count("nc." + map_name + ".expirations=0")) self.assertEqual(1, result.count("nc." + map_name + ".invalidations=0")) self.assertEqual( 1, result.count("nc." + map_name + ".invalidationRequests=0")) test_map.put(1, 2) # invalidation request test_map.get(1) # cache miss test_map.get(1) # cache hit test_map.put(1, 3) # invalidation + invalidation request test_map.get(1) # cache miss time.sleep(2 * self.STATS_PERIOD) response = self._wait_for_statistics_collection(client_uuid) result = response.result.decode("utf-8") self.assertEqual(1, result.count("nc." + map_name + ".evictions=0")) self.assertEqual(1, result.count("nc." + map_name + ".hits=1")) self.assertEqual(1, result.count("nc." + map_name + ".misses=2")) self.assertEqual(1, result.count("nc." + map_name + ".ownedEntryCount=1")) self.assertEqual(1, result.count("nc." + map_name + ".expirations=0")) self.assertEqual(1, result.count("nc." + map_name + ".invalidations=1")) self.assertEqual( 1, result.count("nc." + map_name + ".invalidationRequests=2")) client.shutdown()
def test_statistics_content(self): config = ClientConfig() config.set_property(ClientProperties.STATISTICS_ENABLED.name, True) config.set_property(ClientProperties.STATISTICS_PERIOD_SECONDS.name, self.STATS_PERIOD) map_name = random_string() near_cache_config = NearCacheConfig(map_name) config.near_cache_configs[map_name] = near_cache_config client = HazelcastClient(config) client_uuid = client.cluster.uuid test_map = client.get_map(map_name).blocking() time.sleep(2 * self.STATS_PERIOD) response = self._wait_for_statistics_collection(client_uuid) result = response.result.decode("utf-8") local_address = self._get_local_address(client) # Check near cache and client statistics self.assertEqual(1, result.count("clientName=" + client.name)) self.assertEqual(1, result.count("lastStatisticsCollectionTime=")) self.assertEqual(1, result.count("enterprise=false")) self.assertEqual(1, result.count("clientType=" + CLIENT_TYPE)) self.assertEqual(1, result.count("clientVersion=" + CLIENT_VERSION)) self.assertEqual(1, result.count("clusterConnectionTimestamp=")) self.assertEqual(1, result.count("clientAddress=" + local_address)) self.assertEqual(1, result.count("nc." + map_name + ".creationTime")) self.assertEqual(1, result.count("nc." + map_name + ".evictions")) self.assertEqual(1, result.count("nc." + map_name + ".hits")) self.assertEqual(1, result.count("nc." + map_name + ".misses")) self.assertEqual(1, result.count("nc." + map_name + ".ownedEntryCount")) self.assertEqual(1, result.count("nc." + map_name + ".expirations")) self.assertEqual(1, result.count("nc." + map_name + ".invalidations")) self.assertEqual( 1, result.count("nc." + map_name + ".invalidationRequests")) self.assertEqual( 1, result.count("nc." + map_name + ".ownedEntryMemoryCost")) # Check OS and runtime statistics. We cannot know what kind of statistics will be available # in different platforms. So, first try to get these statistics and then check the # response content s = Statistics(client) psutil_stats = s._get_os_and_runtime_stats() for stat_name in psutil_stats: self.assertEqual(1, result.count(stat_name)) client.shutdown()
def test_near_cache_config(self): config = NearCacheConfig(random_string()) with self.assertRaises(ValueError): config.in_memory_format = 100 with self.assertRaises(ValueError): config.eviction_policy = 100 with self.assertRaises(ValueError): config.time_to_live_seconds = -1 with self.assertRaises(ValueError): config.max_idle_seconds = -1 with self.assertRaises(ValueError): config.eviction_max_size = 0
def test_special_characters(self): config = ClientConfig() config.set_property(ClientProperties.STATISTICS_ENABLED.name, True) config.set_property(ClientProperties.STATISTICS_PERIOD_SECONDS.name, self.STATS_PERIOD) map_name = random_string() + ",t=es\\t" near_cache_config = NearCacheConfig(map_name) config.near_cache_configs[map_name] = near_cache_config client = HazelcastClient(config) client_uuid = client.cluster.uuid test_map = client.get_map(map_name).blocking() time.sleep(2 * self.STATS_PERIOD) response = self._wait_for_statistics_collection(client_uuid) result = response.result.decode("utf-8") unescaped_result = self._unescape_special_chars(result) self.assertEqual(-1, result.find(map_name)) self.assertNotEqual(-1, unescaped_result.find(map_name)) client.shutdown()