示例#1
0
 def test_analyzer(self):
     """Test basic analyzer functionality."""
     index = 'test_index'
     sketch_id = 1
     analyser = sessionizer.SessionizerSketchPlugin(index, sketch_id)
     self.assertIsInstance(analyser, SessionizerSketchPlugin)
     self.assertEqual(index, analyser.index_name)
     self.assertEqual(sketch_id, analyser.sketch.id)
示例#2
0
 def test_zero_events(self):
     """Test the behaviour of the sessionizer when given zero events."""
     with mock.patch.object(SessionizerSketchPlugin,
                            'event_stream',
                            return_value=_create_mock_event(0, 0)):
         index = 'test_index'
         sketch_id = 1
         analyser = sessionizer.SessionizerSketchPlugin(index, sketch_id)
         message = analyser.run()
         self.assertEqual(
             message,
             'Sessionizing completed, number of session created: 0')
示例#3
0
 def test_one_event(self):
     """Test the behaviour of the sessionizer when given one event."""
     with mock.patch.object(SessionizerSketchPlugin,
                            'event_stream',
                            return_value=_create_mock_event(0, 1)):
         index = 'test_index'
         sketch_id = 1
         analyser = sessionizer.SessionizerSketchPlugin(index, sketch_id)
         message = analyser.run()
         self.assertEqual(
             message,
             'Sessionizing completed, number of session created: 1')
         ds = MockDataStore('test', 0)
         event1 = (ds.get_event('test_index', '0', stored_events=True))
         self.assertEqual(event1['_source']['session_number'], 1)
示例#4
0
    def test_edge_time_diff(self):
        """Test events with the edge time difference between them are
        allocated correctly."""
        with mock.patch.object(SessionizerSketchPlugin,
                               'event_stream',
                               return_value=_create_mock_event(
                                   0, 2, time_diffs=[300000000])):
            index = 'test_index'
            sketch_id = 1
            analyser = sessionizer.SessionizerSketchPlugin(index, sketch_id)
            message = analyser.run()
            self.assertEqual(
                message,
                'Sessionizing completed, number of session created: 1')

            ds = MockDataStore('test', 0)
            event1 = (ds.get_event('test_index', '0', stored_events=True))
            self.assertEqual(event1['_source']['session_number'], 1)
            event2 = (ds.get_event('test_index', '101', stored_events=True))
            self.assertEqual(event2['_source']['session_number'], 1)
示例#5
0
    def test_same_session(self):
        """Test multiple events in the same session are allocated correctly."""
        with mock.patch.object(SessionizerSketchPlugin,
                               'event_stream',
                               return_value=_create_mock_event(
                                   0, 2, time_diffs=[200])):
            index = 'test_index'
            sketch_id = 1
            analyser = sessionizer.SessionizerSketchPlugin(index, sketch_id)
            message = analyser.run()
            self.assertEqual(
                message,
                'Sessionizing completed, number of session created: 1')

            ds = MockDataStore('test', 0)
            event1 = (ds.get_event('test_index', '0', stored_events=True))
            self.assertEqual(event1['_source']['session_number'], 1)
            # checking event with id '101' as 100 events have been inserted
            # as 'padding' (see _create_mock_event())
            event2 = (ds.get_event('test_index', '101', stored_events=True))
            self.assertEqual(event2['_source']['session_number'], 1)
示例#6
0
    def test_diff_session(self):
        """Test multiple events in different sessions are allocated
        correctly."""
        with mock.patch.object(SessionizerSketchPlugin,
                               'event_stream',
                               return_value=_create_mock_event(
                                   0, 2, time_diffs=[400000000])):
            index = 'test_index'
            sketch_id = 1
            analyser = sessionizer.SessionizerSketchPlugin(index, sketch_id)
            message = analyser.run()
            self.assertEqual(
                message,
                'Sessionizing completed, number of session created: 2')

            ds = MockDataStore('test', 0)
            event1 = (ds.get_event('test_index', '0', stored_events=True))
            self.assertEqual(event1['_source']['session_number'], 1)

            event2 = (ds.get_event('test_index', '101', stored_events=True))
            self.assertEqual(event2['_source']['session_number'], 2)
            self.check_surrounding_events([101])
示例#7
0
    def test_multiple_sessions(self):
        """Test multiple events, two of which are in the same session and
        one in a different session."""
        with mock.patch.object(SessionizerSketchPlugin,
                               'event_stream',
                               return_value=_create_mock_event(
                                   0, 3, time_diffs=[3000, 400000000])):
            index = 'test_index'
            sketch_id = 1
            analyser = sessionizer.SessionizerSketchPlugin(index, sketch_id)
            message = analyser.run()
            self.assertEqual(
                message,
                'Sessionizing completed, number of session created: 2')

            ds = MockDataStore('test', 0)
            event1 = (ds.get_event('test_index', '0', stored_events=True))
            self.assertEqual(event1['_source']['session_number'], 1)
            event2 = (ds.get_event('test_index', '101', stored_events=True))
            self.assertEqual(event2['_source']['session_number'], 1)
            event3 = (ds.get_event('test_index', '202', stored_events=True))
            self.assertEqual(event3['_source']['session_number'], 2)
            self.check_surrounding_events([202])