Пример #1
0
	def testFindEventIdsForTimeRange(self):
		# Make sure that filtering by time range we get the right ones
		retrieved_ids = self.findEventIdsAndWait([],
			timerange=TimeRange(133, 153))
		self.assertEqual(retrieved_ids, [4, 2, 3]) # TS: [133, 143, 153]

		retrieved_ids = self.findEventIdsAndWait([],
			timerange=TimeRange(163, 163))
		self.assertEqual(retrieved_ids, [5]) # Timestamps: [163]
Пример #2
0
    def testMonitorDeleteNonExistingEvent(self):
        result = []
        mainloop = self.create_mainloop(None)
        events = parse_events("test/data/five_events.js")

        @asyncTestMethod(mainloop)
        def timeout():
            # We want this timeout - we should not get informed
            # about deletions of non-existing events
            mainloop.quit()
            return False

        @asyncTestMethod(mainloop)
        def notify_insert_handler(time_range, events):
            event_ids = [ev.id for ev in events]
            self.client.delete_events([9999999])

        @asyncTestMethod(mainloop)
        def notify_delete_handler(time_range, event_ids):
            mainloop.quit()
            self.fail("Notified about deletion of non-existing events %s",
                      events)

        self.client.install_monitor(TimeRange(125,
                                              145), [], notify_insert_handler,
                                    notify_delete_handler)

        GLib.timeout_add_seconds(5, timeout)
        self.client.insert_events(events)
        mainloop.run()
Пример #3
0
    def testTwoMonitorsDeleteEvents(self):
        result1 = []
        result2 = []
        mainloop = self.create_mainloop()
        events = parse_events("test/data/five_events.js")

        @asyncTestMethod(mainloop)
        def check_ok():
            if len(result1) == 2 and len(result2) == 2:
                mainloop.quit()

        @asyncTestMethod(mainloop)
        def notify_insert_handler1(time_range, events):
            event_ids = [ev.id for ev in events]
            self.client.delete_events(event_ids)

        @asyncTestMethod(mainloop)
        def notify_delete_handler1(time_range, event_ids):
            result1.extend(event_ids)
            check_ok()

        @asyncTestMethod(mainloop)
        def notify_delete_handler2(time_range, event_ids):
            result2.extend(event_ids)
            check_ok()

        self.client.install_monitor(TimeRange(125,
                                              145), [], notify_insert_handler1,
                                    notify_delete_handler1)

        self.client.install_monitor(TimeRange(125, 145), [], lambda x, y: x,
                                    notify_delete_handler2)

        self.client.insert_events(events)
        mainloop.run()

        self.assertEqual(2, len(result1))
        self.assertEqual(2, len(result2))
Пример #4
0
    def NotifyInsert(self, time_range, events):
        """
		Receive notification that a set of events matching the monitor's
		templates has been recorded in the log.
		
		This method is the raw DBus callback and should normally not be
		overridden. Events are received via the *insert_callback*
		argument given in the constructor to this class.
		
		:param time_range: A two-tuple of 64 bit integers with the minimum
		    and maximum timestamps found in *events*. DBus signature (xx)
		:param events: A list of DBus event structs, signature a(asaasay)
		    with the events matching the monitor.
		    See :meth:`ZeitgeistClient.install_monitor`
		"""
        self._insert_callback(TimeRange(time_range[0], time_range[1]),
                              map(self._event_type, events))
Пример #5
0
    def NotifyDelete(self, time_range, event_ids):
        """
		Receive notification that a set of events within the monitor's
		matched time range has been deleted. Note that this notification
		will also be emitted for deleted events that doesn't match the
		event templates of the monitor. It's just the time range which
		is considered here.
		
		This method is the raw DBus callback and should normally not be
		overridden. Events are received via the *delete_callback*
		argument given in the constructor to this class.
		
		:param time_range: A two-tuple of 64 bit integers with the minimum
		    and maximum timestamps found in *events*. DBus signature (xx)
		:param event_ids: A list of event ids. An event id is simply
		    and unsigned 32 bit integer. DBus signature au.
		"""
        self._delete_callback(TimeRange(time_range[0], time_range[1]),
                              event_ids)
Пример #6
0
    def testMonitorDeleteEvents(self):
        result = []
        mainloop = self.create_mainloop()
        events = parse_events("test/data/five_events.js")

        @asyncTestMethod(mainloop)
        def notify_insert_handler(time_range, events):
            event_ids = [ev.id for ev in events]
            self.client.delete_events(event_ids)

        @asyncTestMethod(mainloop)
        def notify_delete_handler(time_range, event_ids):
            mainloop.quit()
            result.extend(event_ids)

        self.client.install_monitor(TimeRange(125,
                                              145), [], notify_insert_handler,
                                    notify_delete_handler)

        self.client.insert_events(events)
        mainloop.run()

        self.assertEqual(2, len(result))