LEFT | RIGHT |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 """Tests for the multi-processing worker process.""" | 3 """Tests for the multi-processing worker process.""" |
4 | 4 |
5 from __future__ import unicode_literals | 5 from __future__ import unicode_literals |
6 | 6 |
7 import unittest | 7 import unittest |
8 | 8 |
9 from dfvfs.lib import errors as dfvfs_errors | 9 from dfvfs.lib import errors as dfvfs_errors |
10 from dfvfs.path import fake_path_spec | 10 from dfvfs.path import fake_path_spec |
11 | 11 |
| 12 from plaso.containers import sessions |
| 13 from plaso.containers import tasks |
12 from plaso.engine import configurations | 14 from plaso.engine import configurations |
13 from plaso.engine import worker | 15 from plaso.engine import worker |
14 from plaso.multi_processing import multi_process_queue | 16 from plaso.multi_processing import multi_process_queue |
15 from plaso.multi_processing import worker_process | 17 from plaso.multi_processing import worker_process |
16 | 18 |
17 from tests import test_lib as shared_test_lib | 19 from tests import test_lib as shared_test_lib |
18 from tests.multi_processing import test_lib | 20 from tests.multi_processing import test_lib |
19 | 21 |
20 | 22 |
21 class TestEventExtractionWorker(worker.EventExtractionWorker): | 23 class TestEventExtractionWorker(worker.EventExtractionWorker): |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 """Tests the _GetStatus function.""" | 66 """Tests the _GetStatus function.""" |
65 test_process = worker_process.WorkerProcess( | 67 test_process = worker_process.WorkerProcess( |
66 None, None, None, None, None, name='TestWorker') | 68 None, None, None, None, None, name='TestWorker') |
67 status_attributes = test_process._GetStatus() | 69 status_attributes = test_process._GetStatus() |
68 | 70 |
69 self.assertIsNotNone(status_attributes) | 71 self.assertIsNotNone(status_attributes) |
70 self.assertEqual(status_attributes['identifier'], 'TestWorker') | 72 self.assertEqual(status_attributes['identifier'], 'TestWorker') |
71 self.assertEqual(status_attributes['last_activity_timestamp'], 0.0) | 73 self.assertEqual(status_attributes['last_activity_timestamp'], 0.0) |
72 self.assertIsNone(status_attributes['number_of_produced_errors']) | 74 self.assertIsNone(status_attributes['number_of_produced_errors']) |
73 | 75 |
74 storage_writer = self._CreateStorageWriter() | 76 session = sessions.Session() |
| 77 storage_writer = self._CreateStorageWriter(session) |
75 knowledge_base = self._CreateKnowledgeBase() | 78 knowledge_base = self._CreateKnowledgeBase() |
76 test_process._parser_mediator = self._CreateParserMediator( | 79 test_process._parser_mediator = self._CreateParserMediator( |
77 storage_writer, knowledge_base) | 80 storage_writer, knowledge_base) |
78 status_attributes = test_process._GetStatus() | 81 status_attributes = test_process._GetStatus() |
79 | 82 |
80 self.assertIsNotNone(status_attributes) | 83 self.assertIsNotNone(status_attributes) |
81 self.assertEqual(status_attributes['identifier'], 'TestWorker') | 84 self.assertEqual(status_attributes['identifier'], 'TestWorker') |
82 self.assertEqual(status_attributes['last_activity_timestamp'], 0.0) | 85 self.assertEqual(status_attributes['last_activity_timestamp'], 0.0) |
83 self.assertEqual(status_attributes['number_of_produced_errors'], 0) | 86 self.assertEqual(status_attributes['number_of_produced_errors'], 0) |
84 | 87 |
85 def testMain(self): | 88 def testMain(self): |
86 """Tests the _Main function.""" | 89 """Tests the _Main function.""" |
87 task_queue = multi_process_queue.MultiProcessingQueue() | 90 task_queue = multi_process_queue.MultiProcessingQueue(timeout=1) |
88 | 91 |
89 configuration = configurations.ProcessingConfiguration() | 92 configuration = configurations.ProcessingConfiguration() |
90 | 93 |
91 test_process = worker_process.WorkerProcess( | 94 test_process = worker_process.WorkerProcess( |
92 task_queue, None, None, None, configuration, name='TestWorker') | 95 task_queue, None, None, None, configuration, name='TestWorker') |
93 test_process._abort = True | 96 test_process._abort = True |
94 | 97 |
95 test_process.start() | 98 test_process.start() |
96 | 99 |
97 def testProcessPathSpec(self): | 100 def testProcessPathSpec(self): |
98 """Tests the _ProcessPathSpec function.""" | 101 """Tests the _ProcessPathSpec function.""" |
99 configuration = configurations.ProcessingConfiguration() | 102 configuration = configurations.ProcessingConfiguration() |
100 | 103 |
101 test_process = worker_process.WorkerProcess( | 104 test_process = worker_process.WorkerProcess( |
102 None, None, None, None, configuration, name='TestWorker') | 105 None, None, None, None, configuration, name='TestWorker') |
103 | 106 |
104 storage_writer = self._CreateStorageWriter() | 107 session = sessions.Session() |
| 108 storage_writer = self._CreateStorageWriter(session) |
105 knowledge_base = self._CreateKnowledgeBase() | 109 knowledge_base = self._CreateKnowledgeBase() |
106 parser_mediator = self._CreateParserMediator(storage_writer, knowledge_base) | 110 parser_mediator = self._CreateParserMediator(storage_writer, knowledge_base) |
107 | 111 |
108 path_spec = fake_path_spec.FakePathSpec(location='/test/file') | 112 path_spec = fake_path_spec.FakePathSpec(location='/test/file') |
109 | 113 |
110 extraction_worker = TestEventExtractionWorker() | 114 extraction_worker = TestEventExtractionWorker() |
111 test_process._ProcessPathSpec(extraction_worker, parser_mediator, path_spec) | 115 test_process._ProcessPathSpec(extraction_worker, parser_mediator, path_spec) |
112 self.assertEqual(parser_mediator._number_of_errors, 0) | 116 self.assertEqual(parser_mediator._number_of_errors, 0) |
113 | 117 |
114 extraction_worker = TestFailureEventExtractionWorker() | 118 extraction_worker = TestFailureEventExtractionWorker() |
115 test_process._ProcessPathSpec(extraction_worker, parser_mediator, path_spec) | 119 test_process._ProcessPathSpec(extraction_worker, parser_mediator, path_spec) |
116 self.assertEqual(parser_mediator._number_of_errors, 0) | 120 self.assertEqual(parser_mediator._number_of_errors, 0) |
117 self.assertTrue(test_process._abort) | 121 self.assertTrue(test_process._abort) |
118 | 122 |
119 test_process._ProcessPathSpec(None, parser_mediator, path_spec) | 123 test_process._ProcessPathSpec(None, parser_mediator, path_spec) |
120 self.assertEqual(parser_mediator._number_of_errors, 1) | 124 self.assertEqual(parser_mediator._number_of_errors, 1) |
121 | 125 |
122 def testProcessTask(self): | 126 def testProcessTask(self): |
123 """Tests the _ProcessTask function.""" | 127 """Tests the _ProcessTask function.""" |
124 storage_writer = self._CreateStorageWriter() | 128 session = sessions.Session() |
| 129 storage_writer = self._CreateStorageWriter(session) |
| 130 knowledge_base = self._CreateKnowledgeBase() |
125 configuration = configurations.ProcessingConfiguration() | 131 configuration = configurations.ProcessingConfiguration() |
126 | 132 |
127 test_process = worker_process.WorkerProcess( | 133 test_process = worker_process.WorkerProcess( |
128 None, storage_writer, None, None, configuration, name='TestWorker') | 134 None, storage_writer, knowledge_base, session.identifier, configuration, |
| 135 name='TestWorker') |
| 136 test_process._parser_mediator = self._CreateParserMediator( |
| 137 storage_writer, knowledge_base) |
129 | 138 |
130 # TODO: add CreateTaskStorage support to FakeStorage. | 139 task = tasks.Task(session_identifier=session.identifier) |
131 with self.assertRaises(NotImplementedError): | 140 test_process._ProcessTask(task) |
132 test_process._ProcessTask(None) | |
133 | 141 |
134 def testStartAndStopProfiling(self): | 142 def testStartAndStopProfiling(self): |
135 """Tests the _StartProfiling and _StopProfiling functions.""" | 143 """Tests the _StartProfiling and _StopProfiling functions.""" |
136 with shared_test_lib.TempDirectory() as temp_directory: | 144 with shared_test_lib.TempDirectory() as temp_directory: |
137 configuration = configurations.ProcessingConfiguration() | 145 configuration = configurations.ProcessingConfiguration() |
138 configuration.profiling.directory = temp_directory | 146 configuration.profiling.directory = temp_directory |
139 configuration.profiling.profilers = set([ | 147 configuration.profiling.profilers = set([ |
140 'memory', 'parsers', 'processing', 'serializers']) | 148 'memory', 'parsers', 'processing', 'serializers']) |
141 | 149 |
142 test_process = worker_process.WorkerProcess( | 150 test_process = worker_process.WorkerProcess( |
143 None, None, None, None, configuration, name='TestWorker') | 151 None, None, None, None, configuration, name='TestWorker') |
144 test_process._extraction_worker = TestEventExtractionWorker() | 152 test_process._extraction_worker = TestEventExtractionWorker() |
145 | 153 |
146 test_process._StartProfiling() | 154 test_process._StartProfiling() |
147 test_process._StopProfiling() | 155 test_process._StopProfiling() |
148 | 156 |
149 def testSignalAbort(self): | 157 def testSignalAbort(self): |
150 """Tests the SignalAbort function.""" | 158 """Tests the SignalAbort function.""" |
151 test_process = worker_process.WorkerProcess( | 159 test_process = worker_process.WorkerProcess( |
152 None, None, None, None, None, name='TestWorker') | 160 None, None, None, None, None, name='TestWorker') |
153 test_process.SignalAbort() | 161 test_process.SignalAbort() |
154 | 162 |
155 | 163 |
156 if __name__ == '__main__': | 164 if __name__ == '__main__': |
157 unittest.main() | 165 unittest.main() |
LEFT | RIGHT |