def test_lifecycle_listener_disconnected(self):
        collector = event_collector()
        member = self.cluster.start_member()
        client = self.create_client()

        client.lifecycle.add_listener(collector)

        member.shutdown()

        self.assertEqual(collector.events, [LIFECYCLE_STATE_DISCONNECTED])
    def test_remove_lifecycle_listener(self):
        collector = event_collector()

        self.cluster.start_member()
        client = self.create_client()
        id = client.lifecycle.add_listener(collector)
        client.lifecycle.remove_listener(id)
        client.shutdown()

        # noinspection PyUnresolvedReferences
        self.assertEqual(collector.events, [])
    def test_add_entry_listener_item_added(self):
        collector = event_collector()
        self.map.add_entry_listener(include_value=True, added=collector)
        self.map.put('key', 'value')

        def assert_event():
            self.assertEqual(len(collector.events), 1)
            event = collector.events[0]
            self.assertEntryEvent(event, key='key', event_type=EntryEventType.added, value='value')

        self.assertTrueEventually(assert_event, 5)
    def test_remove_entry_listener(self):
        collector = event_collector()
        id = self.replicated_map.add_entry_listener(added=collector)

        self.replicated_map.put('key', 'value')
        self.assertTrueEventually(lambda: self.assertEqual(len(collector.events), 1))
        self.replicated_map.remove_entry_listener(id)
        self.replicated_map.put('key2', 'value')

        time.sleep(1)
        self.assertEqual(len(collector.events), 1)
    def test_add_entry_listener_item_evicted(self):
        collector = event_collector()
        self.replicated_map.add_entry_listener(evicted=collector)
        self.replicated_map.put('key', 'value', ttl=1)

        def assert_event():
            self.assertEqual(len(collector.events), 1)
            event = collector.events[0]
            self.assertEntryEvent(event, key='key', event_type=EntryEventType.evicted, old_value='value')

        self.assertTrueEventually(assert_event, 10)
    def test_add_entry_listener_item_added_include_value(self):
        collector = event_collector()
        self.queue.add_listener(include_value=True, item_added=collector)
        self.queue.add('item-value')

        def assert_event():
            self.assertEqual(len(collector.events), 1)
            event = collector.events[0]
            self.assertEqual(event.item, 'item-value')
            self.assertEqual(event.event_type, ItemEventType.added)

        self.assertTrueEventually(assert_event, 5)
    def test_add_entry_listener_with_key(self):
        collector = event_collector()
        id = self.multi_map.add_entry_listener(key='key1', include_value=True, added=collector)
        self.multi_map.put('key2', 'value2')
        self.multi_map.put('key1', 'value1')

        def assert_event():
            self.assertEqual(len(collector.events), 1)
            event = collector.events[0]
            self.assertEntryEvent(event, key='key1', event_type=EntryEventType.added, value='value1')

        self.assertTrueEventually(assert_event, 5)
    def test_lifecycle_listener(self):
        collector = event_collector()
        config = ClientConfig()
        config.lifecycle_listeners = [collector]
        self.cluster.start_member()
        client = self.create_client(config)
        client.shutdown()

        # noinspection PyUnresolvedReferences
        self.assertEqual(collector.events,
                         [LIFECYCLE_STATE_STARTING, LIFECYCLE_STATE_CONNECTED, LIFECYCLE_STATE_SHUTTING_DOWN,
                          LIFECYCLE_STATE_SHUTDOWN])
    def test_add_entry_listener_with_predicate(self):
        collector = event_collector()
        self.replicated_map.add_entry_listener(predicate=SqlPredicate("this == value1"), added=collector)
        self.replicated_map.put('key2', 'value2')
        self.replicated_map.put('key1', 'value1')

        def assert_event():
            self.assertEqual(len(collector.events), 1)
            event = collector.events[0]
            self.assertEntryEvent(event, key='key1', event_type=EntryEventType.added, value='value1')

        self.assertTrueEventually(assert_event, 5)
    def test_add_listener(self):
        collector = event_collector()
        reg_id = self.topic.add_listener(on_message=collector)
        self.topic.publish('item-value')

        def assert_event():
            self.assertEqual(len(collector.events), 1)
            event = collector.events[0]
            self.assertEqual(event.message, 'item-value')
            self.assertGreater(event.publish_time, 0)

        self.assertTrueEventually(assert_event, 5)
    def test_add_entry_listener_clear_all(self):
        collector = event_collector()
        self.replicated_map.add_entry_listener(clear_all=collector)
        self.replicated_map.put('key', 'value')
        self.replicated_map.clear()

        def assert_event():
            self.assertEqual(len(collector.events), 1)
            event = collector.events[0]
            self.assertEntryEvent(event, event_type=EntryEventType.clear_all, number_of_affected_entries=1)

        self.assertTrueEventually(assert_event, 5)
    def test_add_entry_listener_item_removed(self):
        collector = event_collector()
        self.set.add_listener(include_value=False, item_removed=collector)
        self.set.add('item-value')
        self.set.remove('item-value')

        def assert_event():
            self.assertEqual(len(collector.events), 1)
            event = collector.events[0]
            self.assertEqual(event.item, None)
            self.assertEqual(event.event_type, ItemEventType.removed)

        self.assertTrueEventually(assert_event, 5)
    def test_remove_entry_listener_item_added(self):
        collector = event_collector()
        reg_id = self.queue.add_listener(include_value=False, item_added=collector)
        self.queue.remove_listener(reg_id)
        self.queue.add('item-value')

        def assert_event():
            self.assertEqual(len(collector.events), 0)
            if len(collector.events) > 0:
                event = collector.events[0]
                self.assertEqual(event.item, None)
                self.assertEqual(event.event_type, ItemEventType.added)

        self.assertTrueEventually(assert_event, 5)
    def test_listener_re_register(self):
        member = self.cluster.start_member()
        client = self.create_client()

        map = client.get_map("map")

        collector = event_collector()
        reg_id = map.add_entry_listener(added=collector)
        self.logger.info("Registered listener with id %s", reg_id)
        member.shutdown()
        self.cluster.start_member()

        count = AtomicInteger()

        def assert_events():
            map.put("key-%d" % count.get_and_increment(), "value").result()
            self.assertGreater(len(collector.events), 0)

        self.assertTrueEventually(assert_events)
Beispiel #15
0
    def test_remove_distributed_object_listener(self):
        collector = event_collector()
        reg_id = self.client.add_distributed_object_listener(
            listener_func=collector).result()
        m = self.client.get_map("test-map")

        def assert_event():
            self.assertEqual(1, len(collector.events))
            event = collector.events[0]
            self.assertDistributedObjectEvent(
                event, "test-map", MAP_SERVICE,
                DistributedObjectEventType.CREATED)

        self.assertTrueEventually(assert_event)

        response = self.client.remove_distributed_object_listener(
            reg_id).result()
        self.assertTrue(response)
        m.destroy()

        time.sleep(1)

        # We should only receive the map created event
        assert_event()
Beispiel #16
0
 def setUp(self):
     self.client = self.create_client({
         "cluster_name": self.cluster.id,
         "smart_routing": True,
     })
     self.collector = event_collector()
 def setUp(self):
     client_config = ClientConfig()
     client_config.network_config.smart_routing = True
     self.client = self.create_client(client_config)
     self.collector = event_collector()