use of com.alibaba.graphscope.groot.coordinator.BackupService in project GraphScope by alibaba.
the class CoordinatorRpcTest method testBackupService.
@Test
void testBackupService() throws IOException {
BackupManager mockBackupManger = mock(BackupManager.class);
BackupService backupService = new BackupService(mockBackupManger);
when(mockBackupManger.createNewBackup()).thenReturn(6);
StreamObserver<CreateNewBackupResponse> mockCreateObserver = mock(StreamObserver.class);
backupService.createNewBackup(CreateNewBackupRequest.newBuilder().build(), mockCreateObserver);
verify(mockCreateObserver).onNext(CreateNewBackupResponse.newBuilder().setGlobalBackupId(6).build());
verify(mockCreateObserver).onCompleted();
StreamObserver<DeleteBackupResponse> mockDeleteObserver = mock(StreamObserver.class);
backupService.deleteBackup(DeleteBackupRequest.newBuilder().setGlobalBackupId(8).build(), mockDeleteObserver);
verify(mockBackupManger).deleteBackup(8);
verify(mockDeleteObserver).onNext(DeleteBackupResponse.newBuilder().build());
verify(mockDeleteObserver).onCompleted();
StreamObserver<PurgeOldBackupsResponse> mockPurgeObserver = mock(StreamObserver.class);
backupService.purgeOldBackups(PurgeOldBackupsRequest.newBuilder().setKeepAliveNumber(5).build(), mockPurgeObserver);
verify(mockBackupManger).purgeOldBackups(5);
verify(mockPurgeObserver).onNext(PurgeOldBackupsResponse.newBuilder().build());
verify(mockPurgeObserver).onCompleted();
StreamObserver<RestoreFromBackupResponse> mockRestoreObserver = mock(StreamObserver.class);
backupService.restoreFromBackup(RestoreFromBackupRequest.newBuilder().setGlobalBackupId(9).setMetaRestorePath("restore_meta").setStoreRestorePath("restore_store").build(), mockRestoreObserver);
verify(mockBackupManger).restoreFromBackup(9, "restore_meta", "restore_store");
verify(mockRestoreObserver).onNext(RestoreFromBackupResponse.newBuilder().build());
verify(mockRestoreObserver).onCompleted();
StreamObserver<VerifyBackupResponse> mockVerifyObserver = mock(StreamObserver.class);
backupService.verifyBackup(VerifyBackupRequest.newBuilder().setGlobalBackupId(7).build(), mockVerifyObserver);
verify(mockBackupManger).verifyBackup(7);
verify(mockVerifyObserver).onNext(VerifyBackupResponse.newBuilder().build());
verify(mockVerifyObserver).onCompleted();
BackupInfo backupInfo1 = new BackupInfo(1, 10L, GraphDef.newBuilder().setVersion(1L).build().toProto().toByteArray(), new ArrayList<>(), new HashMap<>());
BackupInfo backupInfo2 = new BackupInfo(2, 10L, GraphDef.newBuilder().setVersion(2L).build().toProto().toByteArray(), new ArrayList<>(), new HashMap<>());
when(mockBackupManger.getBackupInfoList()).thenReturn(Arrays.asList(backupInfo1, backupInfo2));
StreamObserver<GetBackupInfoResponse> mockGetInfoObserver = mock(StreamObserver.class);
backupService.getBackupInfo(GetBackupInfoRequest.newBuilder().build(), mockGetInfoObserver);
verify(mockGetInfoObserver).onNext(GetBackupInfoResponse.newBuilder().addBackupInfoList(backupInfo1.toProto()).addBackupInfoList(backupInfo2.toProto()).build());
verify(mockGetInfoObserver).onCompleted();
}
Aggregations