use of io.pravega.shared.controller.event.DeleteScopeEvent in project pravega by pravega.
the class RequestHandlersTest method testDeleteScopeRecursive.
@Test
public void testDeleteScopeRecursive() {
StreamMetadataStore streamStoreSpied = spy(getStore());
KVTableMetadataStore kvtStoreSpied = spy(getKvtStore());
OperationContext ctx = new OperationContext() {
@Override
public long getOperationStartTime() {
return 0;
}
@Override
public long getRequestId() {
return 0;
}
};
UUID scopeId = streamStoreSpied.getScopeId(scope, ctx, executor).join();
doAnswer(x -> {
CompletableFuture<UUID> cf = new CompletableFuture<>();
cf.complete(scopeId);
return cf;
}).when(streamStoreSpied).getScopeId(eq(scope), eq(ctx), eq(executor));
doAnswer(invocation -> {
CompletableFuture<Boolean> cf = new CompletableFuture<>();
cf.complete(false);
return cf;
}).when(streamStoreSpied).isScopeSealed(eq(scope), any(), any());
DeleteScopeTask requestHandler = new DeleteScopeTask(streamMetadataTasks, streamStoreSpied, kvtStoreSpied, kvtTasks, executor);
DeleteScopeEvent event = new DeleteScopeEvent(scope, System.currentTimeMillis(), scopeId);
CompletableFuture<Void> future = CompletableFuture.completedFuture(null).thenComposeAsync(v -> requestHandler.execute(event), executor);
future.join();
}
use of io.pravega.shared.controller.event.DeleteScopeEvent in project pravega by pravega.
the class StreamMetadataTasksTest method deleteScopeRecursiveTest.
@Test
public void deleteScopeRecursiveTest() {
WriterMock requestEventWriter = new WriterMock(streamMetadataTasks, executor);
StreamMetadataStore storeSpy = spy(getStore());
final String testDeleteScope = "testDelete";
// Call deleteScopeRecursive() without creating a scope
Controller.DeleteScopeStatus.Status status = streamMetadataTasks.deleteScopeRecursive(testDeleteScope, 123L).join();
assertEquals(status, Controller.DeleteScopeStatus.Status.SUCCESS);
streamStorePartialMock.createScope(testDeleteScope, null, executor).join();
streamMetadataTasks.setRequestEventWriter(requestEventWriter);
DeleteScopeEvent deleteScopeEvent = new DeleteScopeEvent(SCOPE, 2L, UUID.randomUUID());
requestEventWriter.writeEvent(deleteScopeEvent);
doAnswer(x -> {
CompletableFuture<Boolean> future = new CompletableFuture<>();
future.complete(true);
return future;
}).when(spy(storeSpy)).isScopeSealed(testDeleteScope, null, executor);
doAnswer(x -> {
CompletableFuture<UUID> future = new CompletableFuture<>();
future.complete(UUID.randomUUID());
return future;
}).when(spy(storeSpy)).getScopeId(testDeleteScope, null, executor);
consumer.deleteScopeRecursive(SCOPE, 123L).join();
}
use of io.pravega.shared.controller.event.DeleteScopeEvent in project pravega by pravega.
the class RequestHandlersTest method scopeDeleteTest.
@Test
public void scopeDeleteTest() {
final String testScope = "testScope";
final String testStream = "testStream";
final String testRG = "_RGTestRG";
final String testKVT = "testKVT";
StreamMetadataStore streamStoreSpied = spy(getStore());
KVTableMetadataStore kvtStoreSpied = spy(getKvtStore());
StreamMetadataTasks streamMetadataTasks1 = mock(StreamMetadataTasks.class);
TableMetadataTasks kvtTasksMocked = mock(TableMetadataTasks.class);
streamStoreSpied.createScope(testScope, null, executor).join();
OperationContext ctx = new OperationContext() {
@Override
public long getOperationStartTime() {
return 0;
}
@Override
public long getRequestId() {
return 0;
}
};
UUID scopeId = streamStoreSpied.getScopeId(testScope, ctx, executor).join();
doAnswer(x -> {
CompletableFuture<UUID> cf = new CompletableFuture<>();
cf.complete(scopeId);
return cf;
}).when(streamStoreSpied).getScopeId(eq(testScope), eq(ctx), eq(executor));
doAnswer(invocation -> {
CompletableFuture<Boolean> cf = new CompletableFuture<>();
cf.complete(true);
return cf;
}).when(streamStoreSpied).isScopeSealed(eq(testScope), any(), any());
createStreamInStore(testStream, testScope);
createStreamInStore(testRG, testScope);
assertTrue(streamStore.checkStreamExists(testScope, testStream, ctx, executor).join());
doAnswer(invocation -> {
CompletableFuture<Controller.UpdateStreamStatus.Status> future = new CompletableFuture<>();
future.complete(Controller.UpdateStreamStatus.Status.SUCCESS);
return future;
}).when(streamMetadataTasks1).sealStream(anyString(), anyString(), anyLong());
doAnswer(invocation -> {
CompletableFuture<Controller.DeleteStreamStatus.Status> future = new CompletableFuture<>();
future.complete(Controller.DeleteStreamStatus.Status.SUCCESS);
return future;
}).when(streamMetadataTasks1).deleteStream(anyString(), anyString(), anyLong());
// Create Reader Group
ReaderGroupConfig rgConfig = ReaderGroupConfig.builder().stream(NameUtils.getScopedStreamName(testScope, testStream)).build();
final ReaderGroupConfig config = ReaderGroupConfig.cloneConfig(rgConfig, UUID.randomUUID(), 123L);
Controller.ReaderGroupConfiguration expectedConfig = ModelHelper.decode(testScope, testRG, config);
doAnswer(invocationOnMock -> {
CompletableFuture<Controller.CreateReaderGroupResponse.Status> createRG = new CompletableFuture<>();
createRG.complete(Controller.CreateReaderGroupResponse.Status.SUCCESS);
return createRG;
}).when(streamMetadataTasks1).createReaderGroup(anyString(), any(), any(), anyLong(), anyLong());
doAnswer(invocation -> CompletableFuture.completedFuture(Controller.ReaderGroupConfigResponse.newBuilder().setStatus(Controller.ReaderGroupConfigResponse.Status.SUCCESS).setConfig(expectedConfig).build())).when(streamMetadataTasks1).getReaderGroupConfig(eq(testScope), anyString(), anyLong());
doAnswer(invocationOnMock -> {
CompletableFuture<Controller.DeleteReaderGroupStatus.Status> future = new CompletableFuture<>();
future.complete(Controller.DeleteReaderGroupStatus.Status.SUCCESS);
return future;
}).when(streamMetadataTasks1).deleteReaderGroup(anyString(), anyString(), anyString(), anyLong());
// Create KVT
KeyValueTableConfiguration kvtConfig = KeyValueTableConfiguration.builder().partitionCount(1).primaryKeyLength(1).secondaryKeyLength(1).build();
doAnswer(invocationOnMock -> {
CompletableFuture<Controller.CreateKeyValueTableStatus.Status> fut = new CompletableFuture<>();
fut.complete(Controller.CreateKeyValueTableStatus.Status.SUCCESS);
return fut;
}).when(kvtTasksMocked).createKeyValueTable(anyString(), anyString(), any(), anyLong(), anyLong());
List<String> tableList = new ArrayList<>();
tableList.add(testKVT);
Pair<List<String>, String> listOfKVTables = new ImmutablePair<>(tableList, "");
doAnswer(invocationOnMock -> CompletableFuture.completedFuture(listOfKVTables)).doAnswer(invocationOnMock -> CompletableFuture.completedFuture(new ImmutablePair<>(Collections.emptyList(), invocationOnMock.getArgument(0)))).when(kvtStoreSpied).listKeyValueTables(anyString(), any(), anyInt(), any(), any());
doAnswer(invocationOnMock -> {
CompletableFuture<Controller.DeleteKVTableStatus.Status> future = new CompletableFuture<>();
future.complete(Controller.DeleteKVTableStatus.Status.SUCCESS);
return future;
}).when(kvtTasksMocked).deleteKeyValueTable(anyString(), anyString(), anyLong());
Controller.CreateKeyValueTableStatus.Status status = kvtTasksMocked.createKeyValueTable(testScope, testKVT, kvtConfig, System.currentTimeMillis(), 123L).join();
assertEquals(status, Controller.CreateKeyValueTableStatus.Status.SUCCESS);
DeleteScopeTask requestHandler = new DeleteScopeTask(streamMetadataTasks1, streamStoreSpied, kvtStoreSpied, kvtTasksMocked, executor);
DeleteScopeEvent event = new DeleteScopeEvent(testScope, 123L, scopeId);
CompletableFuture<Void> future = requestHandler.execute(event);
future.join();
}
use of io.pravega.shared.controller.event.DeleteScopeEvent in project pravega by pravega.
the class StreamMetadataTasksTest method testAddIndexAndSubmitTask.
@Test(timeout = 10000)
public void testAddIndexAndSubmitTask() {
WriterMock requestEventWriter = new WriterMock(streamMetadataTasks, executor);
streamMetadataTasks.setRequestEventWriter(requestEventWriter);
UpdateStreamEvent updateEvent = new UpdateStreamEvent("scope", "stream", 0L);
AssertExtensions.assertFutureThrows("throw Connection error", streamMetadataTasks.addIndexAndSubmitTask(updateEvent, () -> Futures.failedFuture(StoreException.create(StoreException.Type.CONNECTION_ERROR, "Connection"))), e -> Exceptions.unwrap(e) instanceof StoreException.StoreConnectionException);
// verify that the event is posted
assertFalse(requestEventWriter.eventQueue.isEmpty());
assertEquals(requestEventWriter.eventQueue.poll(), updateEvent);
TruncateStreamEvent truncateEvent = new TruncateStreamEvent("scope", "stream", 0L);
AssertExtensions.assertFutureThrows("throw write conflict", streamMetadataTasks.addIndexAndSubmitTask(truncateEvent, () -> Futures.failedFuture(StoreException.create(StoreException.Type.WRITE_CONFLICT, "write conflict"))), e -> Exceptions.unwrap(e) instanceof StoreException.WriteConflictException);
// verify that the event is posted
assertFalse(requestEventWriter.eventQueue.isEmpty());
assertEquals(requestEventWriter.eventQueue.poll(), truncateEvent);
AssertExtensions.assertFutureThrows("any other exception", streamMetadataTasks.addIndexAndSubmitTask(truncateEvent, () -> Futures.failedFuture(StoreException.create(StoreException.Type.DATA_NOT_FOUND, "data not found"))), e -> Exceptions.unwrap(e) instanceof StoreException.DataNotFoundException);
// no event should be posted for any other failure
assertTrue(requestEventWriter.eventQueue.isEmpty());
DeleteScopeEvent deleteScopeEvent = new DeleteScopeEvent("testScope", 123L, UUID.randomUUID());
assertEquals("testScope", deleteScopeEvent.getKey());
AssertExtensions.assertFutureThrows("throw write conflict", streamMetadataTasks.addIndexAndSubmitTask(deleteScopeEvent, () -> Futures.failedFuture(StoreException.create(StoreException.Type.WRITE_CONFLICT, "write conflict"))), e -> Exceptions.unwrap(e) instanceof StoreException.WriteConflictException);
// verify that the event is posted
assertFalse(requestEventWriter.eventQueue.isEmpty());
assertEquals(requestEventWriter.eventQueue.poll(), deleteScopeEvent);
}
Aggregations