예제 #1
0
    def test_event_persist(self):
        events = [{'_id': '778dcc0811bd4b518ffd1ef873f3f457',
                   'base_types': ['Event'],
                   'description': 'Event to deliver the status of instrument.',
                   'origin': 'instrument_1',
                   'origin_type': 'PlatformDevice',
                   'status': 1,
                   'sub_type': 'input_voltage',
                   'time_stamps': [2.0, 2.0],
                   'ts_created': '1364121284585',
                   'type_': 'DeviceStatusEvent',
                   'valid_values': [-100, 100],
                   'values': [110.0, 111.0]},
                  {'_id': 'b40731684e41418082e1727f3cf61026',
                   'base_types': ['Event'],
                   'description': 'Event to deliver the status of instrument.',
                   'origin': 'instrument_1',
                   'origin_type': 'PlatformDevice',
                   'status': 1,
                   'sub_type': 'input_voltage',
                   'time_stamps': [2.0, 2.0],
                   'ts_created': '1364121284609',
                   'type_': 'DeviceStatusEvent',
                   'valid_values': [-100, 100],
                   'values': [110.0, 111.0]}]

        dsm = DatastoreManager()
        ds = dsm.get_datastore("events", "EVENTS")
        ds.delete_datastore()
        ds.create_datastore()

        event_repo = EventRepository(dsm)

        event1_dict = events[0].copy()
        event1_dict.pop("_id")
        event1_type = event1_dict.pop("type_")
        event1 = IonObject(event1_type, **event1_dict)
        event_repo.put_event(event1)

        events_r = event_repo.find_events(origin=event1_dict["origin"])
        self.assertEquals(len(events_r), 1)
        event1_read = events_r[0][2]
        self.assertEquals(event1_read.time_stamps, event1_dict["time_stamps"])

        event2_dict = events[1].copy()
        event2_id = event2_dict.pop("_id")
        event2_type = event2_dict.pop("type_")
        event2_obj = IonObject(event2_type, **event2_dict)
        event2_obj._id = event2_id
        event_repo.put_event(event2_obj)

        event1_dict = events[0].copy()
        event1_id = event1_dict.pop("_id")
        event1_type = event1_dict.pop("type_")
        event1_obj = IonObject(event1_type, **event1_dict)
        event1_obj._id = event1_id

        event2_dict = events[1].copy()
        event2_id = event2_dict.pop("_id")
        event2_type = event2_dict.pop("type_")
        event2_obj = IonObject(event2_type, **event2_dict)
        event2_obj._id = event2_id

        event_repo.put_events([event1_obj, event2_obj])
        events_r = event_repo.find_events(event_type='DeviceStatusEvent')
        self.assertEquals(len(events_r), 3)
예제 #2
0
    def test_event_persist(self):
        events = [{
            '_id': '778dcc0811bd4b518ffd1ef873f3f457',
            'base_types': ['Event', 'ResourceEvent'],
            'description': 'Event to deliver the status of instrument.',
            'origin': 'instrument_1',
            'origin_type': 'PlatformDevice',
            'sub_type': 'input_voltage',
            'ts_created': '1364121284585',
            'type_': 'ResourceLifecycleEvent'
        }, {
            '_id': 'b40731684e41418082e1727f3cf61026',
            'base_types': ['Event', 'ResourceEvent'],
            'description': 'Event to deliver the status of instrument.',
            'origin': 'instrument_1',
            'origin_type': 'PlatformDevice',
            'sub_type': 'input_voltage',
            'ts_created': '1364121284609',
            'type_': 'ResourceModifiedEvent'
        }]

        dsm = DatastoreManager()
        ds = dsm.get_datastore(DataStore.DS_EVENTS,
                               DataStore.DS_PROFILE.EVENTS)
        ds.delete_datastore()
        ds.create_datastore()

        event_repo = EventRepository(dsm)

        # Store one event without ID
        event1_dict = events[0].copy()
        event1_dict.pop("_id")
        event1_type = event1_dict.pop("type_")
        event1 = IonObject(event1_type, **event1_dict)
        event_repo.put_event(event1)

        events_r = event_repo.find_events(origin=event1_dict["origin"])
        self.assertEquals(len(events_r), 1)
        event1_read = events_r[0][2]

        # Store one event with ID
        event2_dict = events[1].copy()
        event2_id = event2_dict.pop("_id")
        event2_type = event2_dict.pop("type_")
        event2_obj = IonObject(event2_type, **event2_dict)
        event2_obj._id = event2_id
        event_repo.put_event(event2_obj)

        # Store multiple new events with ID set and unset, non-existing
        event1_dict = events[0].copy()
        event1_id = event1_dict.pop("_id")
        event1_type = event1_dict.pop("type_")
        event1_obj = IonObject(event1_type, **event1_dict)
        event1_obj._id = create_unique_event_id()

        event2_dict = events[1].copy()
        event2_id = event2_dict.pop("_id")
        event2_type = event2_dict.pop("type_")
        event2_obj = IonObject(event2_type, **event2_dict)

        event_repo.put_events([event1_obj, event2_obj])
        events_r = event_repo.find_events(event_type='ResourceModifiedEvent')
        self.assertEquals(len(events_r), 2)
예제 #3
0
    def test_event_repo(self):
        dsm = DatastoreManager()
        ds = dsm.get_datastore("events", "EVENTS")
        ds.delete_datastore()
        ds.create_datastore()

        event_repo = EventRepository(dsm)
        event_repo1 = EventRepository(dsm)

        event1 = Event(origin="resource1")
        event_id, _ = event_repo.put_event(event1)

        event1r = event_repo.get_event(event_id)
        self.assertEquals(event1.origin, event1r.origin)

        ts = 1328680477138
        events2 = []
        for i in xrange(5):
            ev = Event(origin="resource2", ts_created=str(ts + i))
            event_id, _ = event_repo.put_event(ev)
            events2.append((ev,event_id))

        events_r = event_repo.find_events(origin='resource2')
        self.assertEquals(len(events_r), 5)

        events_r = event_repo.find_events(origin='resource2', descending=True)
        self.assertEquals(len(events_r), 5)

        events_r = event_repo.find_events(origin='resource2', limit=3)
        self.assertEquals(len(events_r), 3)

        events_r = event_repo.find_events(origin='resource2', start_ts=str(ts+3))
        self.assertEquals(len(events_r), 2)

        events_r = event_repo.find_events(origin='resource2', end_ts=str(ts+2))
        self.assertEquals(len(events_r), 3)

        events_r = event_repo.find_events(origin='resource2', start_ts=str(ts+3), end_ts=str(ts+4))
        self.assertEquals(len(events_r), 2)

        events_r = event_repo.find_events(start_ts=str(ts+3), end_ts=str(ts+4))
        self.assertEquals(len(events_r), 2)

        event3 = ResourceLifecycleEvent(origin="resource3")
        event_id, _ = event_repo.put_event(event3)

        events_r = event_repo.find_events(event_type="ResourceLifecycleEvent")
        self.assertEquals(len(events_r), 1)
예제 #4
0
    def test_event_repo(self):
        dsm = DatastoreManager()
        ds = dsm.get_datastore("events", "EVENTS")
        ds.delete_datastore()
        ds.create_datastore()

        event_repo = EventRepository(dsm)
        event_repo1 = EventRepository(dsm)

        event1 = Event(origin="resource1")
        event_id = event_repo.put_event(event1)

        event1r = event_repo.get_event(event_id)
        self.assertEquals(event1.origin, event1r.origin)

        ts = 1328680477138
        events2 = []
        for i in xrange(5):
            ev = Event(origin="resource2", ts_created=str(ts + i))
            event_id = event_repo.put_event(ev)
            events2.append((ev, event_id))

        events_r = event_repo.find_events(origin='resource2')
        self.assertEquals(len(events_r), 5)

        events_r = event_repo.find_events(origin='resource2', descending=True)
        self.assertEquals(len(events_r), 5)

        events_r = event_repo.find_events(origin='resource2', limit=3)
        self.assertEquals(len(events_r), 3)

        events_r = event_repo.find_events(origin='resource2',
                                          start_ts=str(ts + 3))
        self.assertEquals(len(events_r), 2)

        events_r = event_repo.find_events(origin='resource2',
                                          end_ts=str(ts + 2))
        self.assertEquals(len(events_r), 3)

        events_r = event_repo.find_events(origin='resource2',
                                          start_ts=str(ts + 3),
                                          end_ts=str(ts + 4))
        self.assertEquals(len(events_r), 2)

        events_r = event_repo.find_events(start_ts=str(ts + 3),
                                          end_ts=str(ts + 4))
        self.assertEquals(len(events_r), 2)

        event3 = ResourceLifecycleEvent(origin="resource3")
        event_id = event_repo.put_event(event3)

        events_r = event_repo.find_events(event_type="ResourceLifecycleEvent")
        self.assertEquals(len(events_r), 1)