def test_count(self): n = 500 for i in range(n): d = self._new_data() buffer_server.append(self.pid, Record(data=d, timestamp=i, rownum=None)) self.assertEqual(buffer_server.count(self.pid), n)
def test_count(self): """Test that the count of records is correct.""" n_records = 500 for i, data in enumerate(mock_data(n_records, self.channel_count)): buffer_server.append(self.pid, Record(data=data, timestamp=i, rownum=None)) self.assertEqual(buffer_server.count(self.pid), n_records)
def test_multiple_servers(self): """Test multiple concurrent servers.""" pid2 = buffer_server.start(self.channels, self._next_buf_name()) n_records = 200 for count, data in enumerate(mock_data(n_records, self.channel_count)): if count % 2 == 0: buffer_server.append(self.pid, Record(data, count, None)) else: buffer_server.append(pid2, Record(data, count, None)) self.assertEqual(buffer_server.count(self.pid), n_records / 2) self.assertEqual(buffer_server.count(pid2), n_records / 2) server1_data = buffer_server.get_data(self.pid, 0, 5) server2_data = buffer_server.get_data(pid2, 0, 5) self.assertNotEqual(server1_data, server2_data) buffer_server.stop(pid2)
def test_multiple_servers(self): pid2 = buffer_server.start(self.channels, self._next_buf_name()) n = 200 for i in range(n): d = [ np.random.uniform(-1000, 1000) for cc in range(self.channel_count) ] if i % 2 == 0: buffer_server.append(self.pid, Record(d, i, None)) else: buffer_server.append(pid2, Record(d, i, None)) self.assertEqual(buffer_server.count(self.pid), n / 2) self.assertEqual(buffer_server.count(pid2), n / 2) server1_data = buffer_server.get_data(self.pid, 0, 5) server2_data = buffer_server.get_data(pid2, 0, 5) self.assertNotEqual(server1_data, server2_data) buffer_server.stop(pid2)
def get_data_len(self): """Efficient way to calculate the amount of data cached.""" if self._buf is None: return 0 return buffer_server.count(self._buf)