Esempio n. 1
0
class GeneralTest(unittest.TestCase):
	def setUp(self):
		self.hc = HazelcastClient("localhost",5701)

	def test_01_instances(self):
		print self.hc.instances()
	def test_02_members(self):
		print self.hc.members()
	def test_03_destroy(self):
		assert self.hc.destroy("map","mymap") == True , "destroy failed" 
	def test_04_ping(self):
		assert self.hc.ping() == True, "ping failed"
	def tearDown(self):
		self.hc.close()
Esempio n. 2
0
class QueueTest(unittest.TestCase):
	def setUp(self):
		self.hc = HazelcastClient("localhost",5701)
		self.queue = self.hc.getQueue("myqueue")
	def test_01_offer(self):
		assert self.queue.offer(11) == True , "offer failed"
	def test_02_peek(self):
		assert self.queue.peek() == 11 , "peek failed"
	def test_03_entries(self):
		entries =  self.queue.entries()
		self.queue.offer(145)
		entries.append(145)
		assert self.queue.entries() == entries, "retrieving entries failed"
		self.queue.remove(145)
		entries.remove(145)
		assert sorted(self.queue.entries()) == sorted(entries) , "retrieving entries failed"
	def test_04_size(self):
		size = self.queue.size()
		self.queue.offer(1)
		assert self.queue.size() == size + 1 , "size is wrong"
		self.queue.remove(1)
		assert self.queue.size() == size , "size is wrong"
	def test_05_take(self):
		self.queue.offer(21)
		assert	self.queue.take() == 21 , "take failed"
	def test_06_poll(self):
		assert self.queue.poll() == 11, "poll failed"
	def test_07_remove(self):
		self.queue.offer(123)
		assert self.queue.remove(123) == True, "remove failed"
	def test_08_remainingCapacity(self):
		remcap = self.queue.remainingCapacity()
		self.queue.offer(123)
		assert self.queue.remainingCapacity() == remcap -1 , "retrieving remcap failed" 
	def tearDown(self):
		self.hc.close()
Esempio n. 3
0
class MapTest(unittest.TestCase):
    def setUp(self):
        self.hc = HazelcastClient("localhost",5701)
        self.map = self.hc.getMap("mymap")
    def test_01_put(self):
    	result = self.map.put(1,111)
        print result
    	assert (result in [True,111]) == True, "put failed"
    def test_02_get(self):
    	assert self.map.get(1) == 111 ,"get failed"
    def test_03_set(self):
    	self.map.set(12,13)
    	assert self.map.get(12) == 13 , "set failed"
    def test_04_containsKey(self):
    	assert self.map.containsKey(12) == True , "conatinsKey failed"
    def test_05_containsValue(self):
        return True
    	assert self.map.containsValue(13) == True , "conatinsValue failed"
    def test_06_keySet(self):
        return True
    	self.map.put(13,14)
    	self.map.put(14,15)
    	assert set([13,14]).issubset(self.map.keySet())  == True , "retrieving keySet failed"
    def test_07_getAll(self):
        return True
    	assert set([13,14,15]).issubset(self.map.getAll(self.map.keySet())) == True, "getAll failed"
    def test_08_putAll(self):
        return True
    	y={}
    	for x in range(1,4):
  			y[x]=x
    	self.map.putAll(y)
    	assert set(y.keys()).issubset(self.map.keySet())  == True, "putAll failed" 
    def test_09_addListener(self):
        return True
        listenedMapName = "listenerTest1"
        class MapListener(MapEntryListener):
            def entryAdded(self,event):
                print "entry added"
                print "key->" , event.key
                print "value->" , event.value
                assert event.key == 1 , "key is wrong"
                assert event.value == 1, "value is wrong"
            def entryRemoved(self, event):
                print "entry removed"
                print "key->" , event.key
                print "value->" , event.value
                assert event.key == 1 , "key is wrong"
                assert event.value == 2, "value is wrong"
            def entryUpdated(self,event):
                print "entry updated"
                print "key->" , event.key
                print "value->" , event.value
                print "oldValue->" , event.oldValue
                assert event.key == 1 , "key is wrong"
                assert event.value == 2, "value is wrong"
                assert event.oldValue == 1, "oldValue is wrong"
            def entryEvicted(self, event):
                print "entry evicted"
                print "key->" , event.key
                assert event.key == 1 , "key is wrong"
                done.set()
        class ListenerThread(threading.Thread):
            def run(self):
                hc = HazelcastClient()
                mymap = hc.getMap(listenedMapName)
                mymap.addListener(MapListener(),None,True)
        lt = ListenerThread()
        lt.start()
        time.sleep(2)
        done = threading.Event()
        self.hc.getMap(listenedMapName).put(1,1)
        self.hc.getMap(listenedMapName).put(1,2)
        self.hc.getMap(listenedMapName).remove(1)
        self.hc.getMap(listenedMapName).put(1,1)
        self.hc.getMap(listenedMapName).evict(1)
        done.wait()

    def test_11_Remove(self):
        return True        
    	assert self.map.remove(12) == 13 , "remove failed"
    def tearDown(self):
    	self.hc.close()