def test_ValidateFileServer_error(self): blob_size = self.server_size * 2 error_blob_spec = binary_data_pb2.BlobSpec(size=blob_size, chunk_count=1) response = self.server.ValidateFileServer(error_blob_spec, self.context) self.assertTrue(response.error.has_occured)
def test_get_chunk_size(self): blob_size = 10101 chunk_count = 10 chunk_size = math.ceil(blob_size / chunk_count) # Overestimate chunk_size blob_spec = binary_data_pb2.BlobSpec(size=blob_size, chunk_count=chunk_count) self.assertEqual(chunk_size, device.get_chunk_size(blob_spec))
def setUpClass(cls): cls.server_size = 100 cls.blob_spec = binary_data_pb2.BlobSpec(size=1, chunk_count=1) cls.context = None cls.default_filename = 'tests/test_empty.json' cls.server = FileServerServicer(cls.server_size, cls.default_filename) cls.blob_id = binary_data_pb2.BlobId(id=42) cls.chunk_index = 0 cls.payload = b"bag of bits" cls.chunk_spec = binary_data_pb2.ChunkSpec(blob_id=cls.blob_id, index=cls.chunk_index) cls.chunk = binary_data_pb2.Chunk(blob_id=cls.blob_id, index=cls.chunk_index, payload=cls.payload)
def test_create_blob_spec(self): # Get info on the data we are going to work with image_filename = 'images/cat.png' blob_size = os.stat(image_filename).st_size # File size in bytes chunk_count = 10 chunk_size = math.ceil(blob_size / chunk_count) # Overestimate chunk_size # Create the Blob to store the cat image expected_blob_spec = binary_data_pb2.BlobSpec(size=blob_size, chunk_count=chunk_count) blob_spec = device.create_blob_spec(image_filename) self.assertEqual(expected_blob_spec, blob_spec)
def setUpClass(cls): cls.server = get_grpc_server() cls.server_size = 1500000 cls.blob_spec = binary_data_pb2.BlobSpec(size=2, chunk_count=1) cls.context = None cls.device_filename = 'tests/test_store_blob_info.json' cls.default_filename = 'tests/test_empty.json' start_file_server(cls.server, cls.server_size, cls.default_filename) cls.stub = get_file_server_stub() cls.servicer = UploadServicer(cls.stub, cls.device_filename) cls.blob_id = binary_data_pb2.BlobId(id=42) cls.chunk_index = 0 cls.payload = b"bag of bits" cls.chunk = binary_data_pb2.Chunk(blob_id=cls.blob_id, index=cls.chunk_index, payload=cls.payload)
def setUpClass(cls): cls.blob_spec = binary_data_pb2.BlobSpec(size=1, chunk_count=1) cls.default_filename = 'tests/test_empty.json' cls.blob_id = binary_data_pb2.BlobId(id=42) cls.valid_until = file_server.get_expiration_time() cls.blob_info = binary_data_pb2.BlobInfo(id=cls.blob_id, valid_until=cls.valid_until, spec=cls.blob_spec) cls.server = get_grpc_server() cls.server_size = 1500000 cls.default_filename = 'tests/test_empty.json' cls.device_filename = 'tests/test_store_blob_info.json' start_file_server(cls.server, cls.server_size, cls.default_filename) cls.stub = get_file_server_stub() cls.upload_servicer = UploadServicer(cls.stub, cls.device_filename) cls.download_servicer = DownloadServicer(get_file_server_stub(), cls.device_filename)