Ejemplo n.º 1
0
    def test_get_snapshot(self):
        stub = IndexStub(self.channel)

        # create snapshot
        request = CreateSnapshotRequest()
        response = stub.CreateSnapshot(request)
        sleep(1)  # wait for snapshot file to be created
        self.assertEqual(True, response.status.success)
        self.assertEqual(True,
                         os.path.exists(self.indexer.get_snapshot_file_name()))

        with zipfile.ZipFile(self.indexer.get_snapshot_file_name()) as f:
            self.assertEqual(['raft.bin'], f.namelist())

        # get snapshot
        request = GetSnapshotRequest()
        request.chunk_size = 1024

        response = stub.GetSnapshot(request)

        download_file_name = self.temp_dir.name + '/snapshot_downloaded.zip'

        with open(download_file_name, 'wb') as f:
            for snapshot in response:
                f.write(snapshot.chunk)

        with zipfile.ZipFile(download_file_name) as f:
            self.assertEqual(['raft.bin'], f.namelist())
Ejemplo n.º 2
0
    def test_create_snapshot(self):
        stub = IndexStub(self.channel)

        self.assertEqual(False,
                         os.path.exists(self.indexer.get_snapshot_file_name()))

        # create snapshot
        request = CreateSnapshotRequest()
        response = stub.CreateSnapshot(request)
        sleep(1)  # wait for snapshot file to be created
        self.assertEqual(True, response.status.success)
        self.assertEqual(True,
                         os.path.exists(self.indexer.get_snapshot_file_name()))

        with zipfile.ZipFile(self.indexer.get_snapshot_file_name()) as f:
            self.assertEqual(['raft.bin'], f.namelist())
Ejemplo n.º 3
0
    def test_snapshot_exists(self):
        stub = IndexStub(self.channel)

        # snapshot exists
        request = IsSnapshotExistRequest()
        response = stub.IsSnapshotExist(request)
        self.assertEqual(True, response.status.success)
        self.assertEqual(False, response.exist)

        # create snapshot
        request = CreateSnapshotRequest()
        response = stub.CreateSnapshot(request)
        sleep(1)  # wait for snapshot file to be created
        self.assertEqual(True, response.status.success)
        self.assertEqual(True,
                         os.path.exists(self.indexer.get_snapshot_file_name()))

        # snapshot exists
        request = IsSnapshotExistRequest()
        response = stub.IsSnapshotExist(request)
        self.assertEqual(True, response.status.success)
        self.assertEqual(True, response.exist)