Search in sources :

Example 1 with WireCommandFailedException

use of io.pravega.controller.server.WireCommandFailedException in project pravega by pravega.

the class PravegaTablesStoreHelper method exceptionalCallback.

private <T> Supplier<CompletableFuture<T>> exceptionalCallback(Supplier<CompletableFuture<T>> future, Supplier<String> errorMessageSupplier, boolean throwOriginalOnCFE, long requestId) {
    return () -> CompletableFuture.completedFuture(null).thenComposeAsync(v -> future.get(), executor).exceptionally(t -> {
        String errorMessage = errorMessageSupplier.get();
        Throwable cause = Exceptions.unwrap(t);
        Throwable toThrow;
        if (cause instanceof WireCommandFailedException) {
            WireCommandFailedException wcfe = (WireCommandFailedException) cause;
            switch(wcfe.getReason()) {
                case ConnectionDropped:
                case ConnectionFailed:
                    toThrow = throwOriginalOnCFE ? wcfe : StoreException.create(StoreException.Type.CONNECTION_ERROR, wcfe, errorMessage);
                    break;
                case UnknownHost:
                    toThrow = StoreException.create(StoreException.Type.CONNECTION_ERROR, wcfe, errorMessage);
                    break;
                case PreconditionFailed:
                    toThrow = StoreException.create(StoreException.Type.ILLEGAL_STATE, wcfe, errorMessage);
                    break;
                case AuthFailed:
                    authToken.set(authHelper.retrieveMasterToken());
                    toThrow = StoreException.create(StoreException.Type.CONNECTION_ERROR, wcfe, errorMessage);
                    break;
                case SegmentDoesNotExist:
                    toThrow = StoreException.create(StoreException.Type.DATA_CONTAINER_NOT_FOUND, wcfe, errorMessage);
                    break;
                case TableSegmentNotEmpty:
                    toThrow = StoreException.create(StoreException.Type.DATA_CONTAINS_ELEMENTS, wcfe, errorMessage);
                    break;
                case TableKeyDoesNotExist:
                    toThrow = StoreException.create(StoreException.Type.DATA_NOT_FOUND, wcfe, errorMessage);
                    break;
                case TableKeyBadVersion:
                    toThrow = StoreException.create(StoreException.Type.WRITE_CONFLICT, wcfe, errorMessage);
                    break;
                default:
                    toThrow = StoreException.create(StoreException.Type.UNKNOWN, wcfe, errorMessage);
            }
        } else if (cause instanceof HostStoreException) {
            log.warn(requestId, "Host Store exception {}", cause.getMessage());
            toThrow = StoreException.create(StoreException.Type.CONNECTION_ERROR, cause, errorMessage);
        } else {
            log.warn(requestId, "exception of unknown type thrown {} ", errorMessage, cause);
            toThrow = StoreException.create(StoreException.Type.UNKNOWN, cause, errorMessage);
        }
        throw new CompletionException(toThrow);
    });
}
Also used : TableSegmentKeyVersion(io.pravega.client.tables.impl.TableSegmentKeyVersion) Cache(io.pravega.controller.store.stream.Cache) OperationContext(io.pravega.controller.store.stream.OperationContext) SegmentHelper(io.pravega.controller.server.SegmentHelper) BiFunction(java.util.function.BiFunction) Exceptions(io.pravega.common.Exceptions) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) HostStoreException(io.pravega.controller.store.host.HostStoreException) BitConverter(io.pravega.common.util.BitConverter) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Unpooled(io.netty.buffer.Unpooled) ArrayList(java.util.ArrayList) TagLogger(io.pravega.common.tracing.TagLogger) ByteBuf(io.netty.buffer.ByteBuf) StoreException(io.pravega.controller.store.stream.StoreException) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) HashTableIteratorItem(io.pravega.client.tables.impl.HashTableIteratorItem) RetryHelper(io.pravega.controller.util.RetryHelper) Charsets(org.apache.curator.shaded.com.google.common.base.Charsets) TableSegmentKey(io.pravega.client.tables.impl.TableSegmentKey) Predicate(java.util.function.Predicate) Collection(java.util.Collection) AsyncIterator(io.pravega.common.util.AsyncIterator) CompletionException(java.util.concurrent.CompletionException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) RetriesExhaustedException(io.pravega.common.util.RetriesExhaustedException) StandardCharsets(java.nio.charset.StandardCharsets) ConnectionDropped(io.pravega.controller.server.WireCommandFailedException.Reason.ConnectionDropped) AbstractMap(java.util.AbstractMap) List(java.util.List) ByteArraySegment(io.pravega.common.util.ByteArraySegment) WireCommandFailedException(io.pravega.controller.server.WireCommandFailedException) TableSegmentEntry(io.pravega.client.tables.impl.TableSegmentEntry) ContinuationTokenAsyncIterator(io.pravega.common.util.ContinuationTokenAsyncIterator) ReferenceCountUtil(io.netty.util.ReferenceCountUtil) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) Futures(io.pravega.common.concurrent.Futures) ConnectionFailed(io.pravega.controller.server.WireCommandFailedException.Reason.ConnectionFailed) GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper) HostStoreException(io.pravega.controller.store.host.HostStoreException) CompletionException(java.util.concurrent.CompletionException) WireCommandFailedException(io.pravega.controller.server.WireCommandFailedException)

Example 2 with WireCommandFailedException

use of io.pravega.controller.server.WireCommandFailedException in project pravega by pravega.

the class PravegaTablesStoreHelperTest method testRetriesExhausted.

@Test
public void testRetriesExhausted() {
    SegmentHelper segmentHelper = spy(SegmentHelperMock.getSegmentHelperMockForTables(executor));
    GrpcAuthHelper authHelper = GrpcAuthHelper.getDisabledAuthHelper();
    PravegaTablesStoreHelper storeHelper = new PravegaTablesStoreHelper(segmentHelper, authHelper, executor, 2);
    CompletableFuture<Void> connectionDropped = Futures.failedFuture(new WireCommandFailedException(WireCommandType.CREATE_TABLE_SEGMENT, WireCommandFailedException.Reason.ConnectionDropped));
    doAnswer(x -> connectionDropped).when(segmentHelper).createTableSegment(anyString(), anyString(), anyLong(), anyBoolean(), anyInt(), anyLong());
    AssertExtensions.assertFutureThrows("ConnectionDropped", storeHelper.createTable("table", 0L), e -> Exceptions.unwrap(e) instanceof StoreException.StoreConnectionException);
    CompletableFuture<Void> connectionFailed = Futures.failedFuture(new WireCommandFailedException(WireCommandType.CREATE_TABLE_SEGMENT, WireCommandFailedException.Reason.ConnectionFailed));
    doAnswer(x -> connectionFailed).when(segmentHelper).createTableSegment(anyString(), anyString(), anyLong(), anyBoolean(), anyInt(), anyLong());
    AssertExtensions.assertFutureThrows("ConnectionFailed", storeHelper.createTable("table", 0L), e -> Exceptions.unwrap(e) instanceof StoreException.StoreConnectionException);
    CompletableFuture<Void> authFailed = Futures.failedFuture(new WireCommandFailedException(WireCommandType.CREATE_TABLE_SEGMENT, WireCommandFailedException.Reason.AuthFailed));
    doAnswer(x -> connectionFailed).when(segmentHelper).createTableSegment(anyString(), anyString(), anyLong(), anyBoolean(), anyInt(), anyLong());
    AssertExtensions.assertFutureThrows("AuthFailed", storeHelper.createTable("table", 0L), e -> Exceptions.unwrap(e) instanceof StoreException.StoreConnectionException);
}
Also used : GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper) WireCommandFailedException(io.pravega.controller.server.WireCommandFailedException) SegmentHelper(io.pravega.controller.server.SegmentHelper) StoreException(io.pravega.controller.store.stream.StoreException) Test(org.junit.Test)

Example 3 with WireCommandFailedException

use of io.pravega.controller.server.WireCommandFailedException in project pravega by pravega.

the class SegmentHelperMock method getSegmentHelperMockForTables.

public static SegmentHelper getSegmentHelperMockForTables(ScheduledExecutorService executor) {
    SegmentHelper helper = getSegmentHelperMock();
    final Object lock = new Object();
    final Map<String, Map<ByteBuffer, TableSegmentEntry>> mapOfTables = new HashMap<>();
    final Map<String, Map<ByteBuffer, Long>> mapOfTablesPosition = new HashMap<>();
    // region create table
    doAnswer(x -> {
        String tableName = x.getArgument(0);
        return CompletableFuture.runAsync(() -> {
            synchronized (lock) {
                mapOfTables.putIfAbsent(tableName, new HashMap<>());
                mapOfTablesPosition.putIfAbsent(tableName, new HashMap<>());
            }
        }, executor);
    }).when(helper).createTableSegment(anyString(), anyString(), anyLong(), anyBoolean(), anyInt(), anyLong());
    // endregion
    // region delete table
    doAnswer(x -> {
        String tableName = x.getArgument(0);
        Boolean mustBeEmpty = x.getArgument(1);
        final WireCommandType type = WireCommandType.DELETE_TABLE_SEGMENT;
        return CompletableFuture.supplyAsync(() -> {
            synchronized (lock) {
                if (!mapOfTables.containsKey(tableName)) {
                    throw new WireCommandFailedException(type, WireCommandFailedException.Reason.SegmentDoesNotExist);
                }
                boolean empty = Optional.ofNullable(mapOfTables.get(tableName)).orElse(Collections.emptyMap()).isEmpty();
                if (!mustBeEmpty || empty) {
                    mapOfTables.remove(tableName);
                    mapOfTablesPosition.remove(tableName);
                    return null;
                } else {
                    throw new WireCommandFailedException(type, WireCommandFailedException.Reason.TableSegmentNotEmpty);
                }
            }
        }, executor);
    }).when(helper).deleteTableSegment(anyString(), anyBoolean(), anyString(), anyLong());
    // endregion
    // region update keys
    doAnswer(x -> {
        final WireCommandType type = WireCommandType.UPDATE_TABLE_ENTRIES;
        String tableName = x.getArgument(0);
        List<TableSegmentEntry> entries = x.getArgument(1);
        return CompletableFuture.supplyAsync(() -> {
            synchronized (lock) {
                Map<ByteBuffer, TableSegmentEntry> table = mapOfTables.get(tableName);
                Map<ByteBuffer, Long> tablePos = mapOfTablesPosition.get(tableName);
                if (table == null) {
                    throw new WireCommandFailedException(type, WireCommandFailedException.Reason.SegmentDoesNotExist);
                } else {
                    List<TableSegmentKeyVersion> resultList = new LinkedList<>();
                    entries.forEach(entry -> {
                        ByteBuffer key = entry.getKey().getKey().copy().nioBuffer();
                        byte[] value = entry.getValue().copy().array();
                        TableSegmentEntry existingEntry = table.get(key);
                        if (existingEntry == null) {
                            if (entry.getKey().getVersion().equals(TableSegmentKeyVersion.NOT_EXISTS)) {
                                TableSegmentEntry newEntry = TableSegmentEntry.versioned(key.array(), value, 0);
                                table.put(key, newEntry);
                                tablePos.put(key, System.nanoTime());
                                resultList.add(newEntry.getKey().getVersion());
                            } else {
                                throw new WireCommandFailedException(type, WireCommandFailedException.Reason.TableKeyDoesNotExist);
                            }
                        } else if (existingEntry.getKey().getVersion().equals(entry.getKey().getVersion())) {
                            TableSegmentKeyVersion newVersion = TableSegmentKeyVersion.from(existingEntry.getKey().getVersion().getSegmentVersion() + 1);
                            TableSegmentEntry newEntry = TableSegmentEntry.versioned(key.array(), value, newVersion.getSegmentVersion());
                            table.put(key, newEntry);
                            tablePos.put(key, System.nanoTime());
                            resultList.add(newVersion);
                        } else {
                            throw new WireCommandFailedException(type, WireCommandFailedException.Reason.TableKeyBadVersion);
                        }
                    });
                    return resultList;
                }
            }
        }, executor);
    }).when(helper).updateTableEntries(anyString(), any(), anyString(), anyLong());
    // endregion
    // region remove keys
    doAnswer(x -> {
        final WireCommandType type = WireCommandType.REMOVE_TABLE_KEYS;
        String tableName = x.getArgument(0);
        List<TableSegmentKey> keys = x.getArgument(1);
        return CompletableFuture.runAsync(() -> {
            synchronized (lock) {
                Map<ByteBuffer, TableSegmentEntry> table = mapOfTables.get(tableName);
                Map<ByteBuffer, Long> tablePos = mapOfTablesPosition.get(tableName);
                if (table == null) {
                    throw new WireCommandFailedException(type, WireCommandFailedException.Reason.SegmentDoesNotExist);
                } else {
                    keys.forEach(rawKey -> {
                        ByteBuffer key = rawKey.getKey().copy().nioBuffer();
                        TableSegmentEntry existingEntry = table.get(key);
                        if (existingEntry != null) {
                            if (existingEntry.getKey().getVersion().equals(rawKey.getVersion()) || rawKey.getVersion() == null || rawKey.getVersion().equals(TableSegmentKeyVersion.NO_VERSION)) {
                                table.remove(key);
                                tablePos.remove(key);
                            } else {
                                throw new WireCommandFailedException(type, WireCommandFailedException.Reason.TableKeyBadVersion);
                            }
                        }
                    });
                }
            }
        }, executor);
    }).when(helper).removeTableKeys(anyString(), any(), anyString(), anyLong());
    // endregion
    // region read keys
    doAnswer(x -> {
        final WireCommandType type = WireCommandType.READ_TABLE;
        String tableName = x.getArgument(0);
        List<TableSegmentKey> requestKeys = x.getArgument(1);
        return CompletableFuture.supplyAsync(() -> {
            synchronized (lock) {
                Map<ByteBuffer, TableSegmentEntry> table = mapOfTables.get(tableName);
                if (table == null) {
                    throw new WireCommandFailedException(type, WireCommandFailedException.Reason.SegmentDoesNotExist);
                } else {
                    List<TableSegmentEntry> resultList = new LinkedList<>();
                    requestKeys.forEach(requestKey -> {
                        ByteBuffer key = requestKey.getKey().copy().nioBuffer();
                        TableSegmentEntry existingEntry = table.get(key);
                        if (existingEntry == null) {
                            resultList.add(TableSegmentEntry.notExists(key.array(), new byte[0]));
                        } else if (existingEntry.getKey().getVersion().equals(requestKey.getVersion()) || requestKey.getVersion() == null || requestKey.getVersion().equals(TableSegmentKeyVersion.NO_VERSION)) {
                            resultList.add(duplicate(existingEntry));
                        } else {
                            throw new WireCommandFailedException(type, WireCommandFailedException.Reason.TableKeyBadVersion);
                        }
                    });
                    return resultList;
                }
            }
        }, executor);
    }).when(helper).readTable(anyString(), any(), anyString(), anyLong());
    // endregion
    // region readTableKeys
    doAnswer(x -> {
        String tableName = x.getArgument(0);
        int limit = x.getArgument(1);
        HashTableIteratorItem.State state = x.getArgument(2);
        final WireCommandType type = WireCommandType.READ_TABLE;
        return CompletableFuture.supplyAsync(() -> {
            synchronized (lock) {
                Map<ByteBuffer, TableSegmentEntry> table = mapOfTables.get(tableName);
                Map<ByteBuffer, Long> tablePos = mapOfTablesPosition.get(tableName);
                if (table == null) {
                    throw new WireCommandFailedException(type, WireCommandFailedException.Reason.SegmentDoesNotExist);
                } else {
                    long floor;
                    if (state.equals(HashTableIteratorItem.State.EMPTY)) {
                        floor = 0L;
                    } else {
                        floor = new ByteArraySegment(state.toBytes()).getLong(0);
                    }
                    AtomicLong token = new AtomicLong(floor);
                    List<TableSegmentKey> list = tablePos.entrySet().stream().sorted(Comparator.comparingLong(Map.Entry::getValue)).filter(c -> c.getValue() > floor).map(r -> {
                        token.set(r.getValue());
                        return duplicate(table.get(r.getKey()).getKey());
                    }).limit(limit).collect(Collectors.toList());
                    byte[] continuationToken = new byte[Long.BYTES];
                    BitConverter.writeLong(continuationToken, 0, token.get());
                    HashTableIteratorItem.State newState = HashTableIteratorItem.State.fromBytes(Unpooled.wrappedBuffer(continuationToken));
                    return new HashTableIteratorItem<>(newState, list);
                }
            }
        }, executor);
    }).when(helper).readTableKeys(anyString(), anyInt(), any(), anyString(), anyLong());
    // endregion
    // region readTableEntries
    doAnswer(x -> {
        String tableName = x.getArgument(0);
        int limit = x.getArgument(1);
        HashTableIteratorItem.State state = x.getArgument(2);
        final WireCommandType type = WireCommandType.READ_TABLE;
        return CompletableFuture.supplyAsync(() -> {
            synchronized (lock) {
                Map<ByteBuffer, TableSegmentEntry> table = mapOfTables.get(tableName);
                Map<ByteBuffer, Long> tablePos = mapOfTablesPosition.get(tableName);
                if (table == null) {
                    throw new WireCommandFailedException(type, WireCommandFailedException.Reason.SegmentDoesNotExist);
                } else {
                    long floor;
                    if (state.equals(HashTableIteratorItem.State.EMPTY)) {
                        floor = 0L;
                    } else {
                        floor = new ByteArraySegment(state.toBytes()).getLong(0);
                    }
                    AtomicLong token = new AtomicLong(floor);
                    List<TableSegmentEntry> list = tablePos.entrySet().stream().sorted(Comparator.comparingLong(Map.Entry::getValue)).filter(c -> c.getValue() > floor).map(r -> {
                        token.set(r.getValue());
                        return duplicate(table.get(r.getKey()));
                    }).limit(limit).collect(Collectors.toList());
                    byte[] continuationToken = new byte[Long.BYTES];
                    BitConverter.writeLong(continuationToken, 0, token.get());
                    HashTableIteratorItem.State newState = HashTableIteratorItem.State.fromBytes(Unpooled.wrappedBuffer(continuationToken));
                    return new HashTableIteratorItem<>(newState, list);
                }
            }
        }, executor);
    }).when(helper).readTableEntries(anyString(), anyInt(), any(), anyString(), anyLong());
    // endregion
    return helper;
}
Also used : TableSegmentKeyVersion(io.pravega.client.tables.impl.TableSegmentKeyVersion) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) SegmentHelper(io.pravega.controller.server.SegmentHelper) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Mockito.spy(org.mockito.Mockito.spy) BitConverter(io.pravega.common.util.BitConverter) ByteBuffer(java.nio.ByteBuffer) Unpooled(io.netty.buffer.Unpooled) NodeUri(io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) HashTableIteratorItem(io.pravega.client.tables.impl.HashTableIteratorItem) WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) HostMonitorConfigImpl(io.pravega.controller.store.host.impl.HostMonitorConfigImpl) LinkedList(java.util.LinkedList) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) Mockito.doReturn(org.mockito.Mockito.doReturn) TableSegmentKey(io.pravega.client.tables.impl.TableSegmentKey) ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) UUID(java.util.UUID) WireCommands(io.pravega.shared.protocol.netty.WireCommands) Collectors(java.util.stream.Collectors) HostStoreFactory(io.pravega.controller.store.host.HostStoreFactory) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) ByteArraySegment(io.pravega.common.util.ByteArraySegment) WireCommandFailedException(io.pravega.controller.server.WireCommandFailedException) TableSegmentEntry(io.pravega.client.tables.impl.TableSegmentEntry) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) TxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.TxnStatus) Optional(java.util.Optional) Comparator(java.util.Comparator) Collections(java.util.Collections) Futures(io.pravega.common.concurrent.Futures) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) ByteArraySegment(io.pravega.common.util.ByteArraySegment) HashMap(java.util.HashMap) WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TableSegmentKey(io.pravega.client.tables.impl.TableSegmentKey) WireCommandFailedException(io.pravega.controller.server.WireCommandFailedException) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) HashTableIteratorItem(io.pravega.client.tables.impl.HashTableIteratorItem) TableSegmentKeyVersion(io.pravega.client.tables.impl.TableSegmentKeyVersion) SegmentHelper(io.pravega.controller.server.SegmentHelper) ByteBuffer(java.nio.ByteBuffer) LinkedList(java.util.LinkedList) TableSegmentEntry(io.pravega.client.tables.impl.TableSegmentEntry) AtomicLong(java.util.concurrent.atomic.AtomicLong) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with WireCommandFailedException

use of io.pravega.controller.server.WireCommandFailedException in project pravega by pravega.

the class RequestHandlersTest method testCommitFailureOnNoSuchSegment.

@Test(timeout = 10000)
public void testCommitFailureOnNoSuchSegment() {
    CommitRequestHandler requestHandler = new CommitRequestHandler(streamStore, streamMetadataTasks, streamTransactionMetadataTasks, bucketStore, executor);
    String noSuchSegment = "noSuchSegment";
    streamStore.createScope(noSuchSegment, null, executor).join();
    streamMetadataTasks.createStream(noSuchSegment, noSuchSegment, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build(), System.currentTimeMillis(), 0L).join();
    UUID txn = streamTransactionMetadataTasks.createTxn(noSuchSegment, noSuchSegment, 30000, 0L, 1024 * 1024L).join().getKey().getId();
    streamStore.sealTransaction(noSuchSegment, noSuchSegment, txn, true, Optional.empty(), "", Long.MIN_VALUE, null, executor).join();
    // 1. set segment helper mock to throw exception
    doAnswer(x -> Futures.failedFuture(new WireCommandFailedException(WireCommandType.NO_SUCH_SEGMENT, WireCommandFailedException.Reason.SegmentDoesNotExist))).when(segmentHelper).mergeTxnSegments(anyString(), anyString(), anyLong(), anyLong(), any(), anyString(), anyLong());
    streamStore.startCommitTransactions(noSuchSegment, noSuchSegment, 100, null, executor).join();
    streamStore.setState(noSuchSegment, noSuchSegment, State.COMMITTING_TXN, null, executor).join();
    assertEquals(State.COMMITTING_TXN, streamStore.getState(noSuchSegment, noSuchSegment, true, null, executor).join());
    CommitEvent event = new CommitEvent(noSuchSegment, noSuchSegment, 0);
    AssertExtensions.assertFutureThrows("", requestHandler.process(event, () -> false), e -> Exceptions.unwrap(e) instanceof IllegalStateException);
    verify(segmentHelper, atLeastOnce()).mergeTxnSegments(anyString(), anyString(), anyLong(), anyLong(), any(), anyString(), anyLong());
}
Also used : CommitEvent(io.pravega.shared.controller.event.CommitEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) WireCommandFailedException(io.pravega.controller.server.WireCommandFailedException) UUID(java.util.UUID) CommitRequestHandler(io.pravega.controller.server.eventProcessor.requesthandlers.CommitRequestHandler) Test(org.junit.Test)

Example 5 with WireCommandFailedException

use of io.pravega.controller.server.WireCommandFailedException in project pravega by pravega.

the class PravegaTablesKVTMetadataStoreTest method testPartiallyDeletedScope.

@Test(timeout = 30000)
public void testPartiallyDeletedScope() throws Exception {
    final String scopeName = "partialScope";
    PravegaTablesStoreHelper storeHelperSpy = spy(new PravegaTablesStoreHelper(segmentHelperMockForTables, GrpcAuthHelper.getDisabledAuthHelper(), executor));
    WireCommandFailedException wcfe = new WireCommandFailedException(WireCommandType.READ_TABLE_KEYS, WireCommandFailedException.Reason.TableKeyDoesNotExist);
    when(storeHelperSpy.getKeysPaginated(anyString(), any(), anyInt(), anyLong())).thenReturn(CompletableFuture.failedFuture(new CompletionException(StoreException.create(StoreException.Type.DATA_NOT_FOUND, wcfe, "kvTablesInScope not found."))));
    StreamMetadataStore testStreamStore = TestStreamStoreFactory.createPravegaTablesStreamStore(PRAVEGA_ZK_CURATOR_RESOURCE.client, executor, storeHelperSpy);
    KVTableMetadataStore testKVStore = TestStreamStoreFactory.createPravegaTablesKVStore(PRAVEGA_ZK_CURATOR_RESOURCE.client, executor, storeHelperSpy);
    OperationContext context = testStreamStore.createScopeContext(scopeName, 0L);
    CompletableFuture<Controller.CreateScopeStatus> createScopeFuture = testStreamStore.createScope(scopeName, context, executor);
    Controller.CreateScopeStatus status = createScopeFuture.get();
    Assert.assertEquals(Controller.CreateScopeStatus.Status.SUCCESS, status.getStatus());
    String token = Controller.ContinuationToken.newBuilder().build().getToken();
    Pair<List<String>, String> kvtList = testKVStore.listKeyValueTables(scopeName, token, 2, context, executor).get();
    Assert.assertEquals(0, kvtList.getKey().size());
    Assert.assertEquals(token, kvtList.getValue());
}
Also used : OperationContext(io.pravega.controller.store.stream.OperationContext) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) PravegaTablesStoreHelper(io.pravega.controller.store.PravegaTablesStoreHelper) CompletionException(java.util.concurrent.CompletionException) List(java.util.List) WireCommandFailedException(io.pravega.controller.server.WireCommandFailedException) Test(org.junit.Test)

Aggregations

WireCommandFailedException (io.pravega.controller.server.WireCommandFailedException)6 SegmentHelper (io.pravega.controller.server.SegmentHelper)4 List (java.util.List)4 Test (org.junit.Test)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Unpooled (io.netty.buffer.Unpooled)3 Futures (io.pravega.common.concurrent.Futures)3 GrpcAuthHelper (io.pravega.controller.server.security.auth.GrpcAuthHelper)3 StoreException (io.pravega.controller.store.stream.StoreException)3 Map (java.util.Map)3 UUID (java.util.UUID)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 ByteBuf (io.netty.buffer.ByteBuf)2 HashTableIteratorItem (io.pravega.client.tables.impl.HashTableIteratorItem)2 TableSegmentEntry (io.pravega.client.tables.impl.TableSegmentEntry)2 TableSegmentKey (io.pravega.client.tables.impl.TableSegmentKey)2 TableSegmentKeyVersion (io.pravega.client.tables.impl.TableSegmentKeyVersion)2 Exceptions (io.pravega.common.Exceptions)2 BitConverter (io.pravega.common.util.BitConverter)2