org.apache.kafka.streams.errors.InvalidStateStoreException Java Examples

The following examples show how to use org.apache.kafka.streams.errors.InvalidStateStoreException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DistributedService.java    From apicurio-registry with Apache License 2.0 6 votes vote down vote up
protected final S serviceForKey(K key) {
    KeyQueryMetadata smeta = streams.queryMetadataForKey(storeName, key, keySerde.serializer());
    if (smeta == null) {
        throw new InvalidStateStoreException(
                "StreamsMetadata is null?! " +
                        "Store-name: " + storeName + " " +
                        "Key: " + key
        );
    }
    if (smeta == KeyQueryMetadata.NOT_AVAILABLE) {
        throw new InvalidStateStoreException(
                "StreamsMetadata is currently unavailable. " +
                        "This can occur during rebalance operations. " +
                        "Store-name: " + storeName + " " +
                        "Key: " + key
        );
    }
    return serviceForHostInfo(smeta.getActiveHost());
}
 
Example #2
Source File: InteractiveQueryService.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve and return a queryable store by name created in the application.
 * @param storeName name of the queryable store
 * @param storeType type of the queryable store
 * @param <T> generic queryable store
 * @return queryable store.
 */
public <T> T getQueryableStore(String storeName, QueryableStoreType<T> storeType) {

	RetryTemplate retryTemplate = new RetryTemplate();

	KafkaStreamsBinderConfigurationProperties.StateStoreRetry stateStoreRetry = this.binderConfigurationProperties.getStateStoreRetry();
	RetryPolicy retryPolicy = new SimpleRetryPolicy(stateStoreRetry.getMaxAttempts());
	FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
	backOffPolicy.setBackOffPeriod(stateStoreRetry.getBackoffPeriod());

	retryTemplate.setBackOffPolicy(backOffPolicy);
	retryTemplate.setRetryPolicy(retryPolicy);

	return retryTemplate.execute(context -> {
		T store = null;

		final Set<KafkaStreams> kafkaStreams = InteractiveQueryService.this.kafkaStreamsRegistry.getKafkaStreams();
		final Iterator<KafkaStreams> iterator = kafkaStreams.iterator();
		Throwable throwable = null;
		while (iterator.hasNext()) {
			try {
				store = iterator.next().store(storeName, storeType);
			}
			catch (InvalidStateStoreException e) {
				// pass through..
				throwable = e;
			}
		}
		if (store != null) {
			return store;
		}
		throw new IllegalStateException("Error when retrieving state store: j " + storeName, throwable);
	});
}
 
Example #3
Source File: OrderService.java    From qcon-microservices with Apache License 2.0 6 votes vote down vote up
/**
 * Perform a "Long-Poll" styled get. This method will attempt to get the value for the passed key
 * blocking until the key is available or passed timeout is reached. Non-blocking IO is used to
 * implement this, but the API will block the calling thread if no data is available
 *
 * @param id - the key of the value to retrieve
 * @param timeout - the timeout for the long-poll
 * @param asyncResponse - async response used to trigger the poll early should the appropriate
 * value become available
 */
@GET
@ManagedAsync
@Path("/orders/{id}")
@Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN})
public void getWithTimeout(@PathParam("id") final String id,
                           @QueryParam("timeout") @DefaultValue(CALL_TIMEOUT) Long timeout,
                           @Suspended final AsyncResponse asyncResponse) {
    setTimeout(timeout, asyncResponse);

    log.info("running GET on this node");
    try {
        Order order = ordersStore().get(id);
        if (order == null) {
            log.info("Delaying get as order not present for id " + id);
            outstandingRequests.put(id, new FilteredResponse<>(asyncResponse, (k, v) -> true));
        } else {
            asyncResponse.resume(order);
        }
    } catch (InvalidStateStoreException e) {
        //Store not ready so delay
        log.info("Delaying request for " + id + " because state store is not ready.");
        outstandingRequests.put(id, new FilteredResponse<>(asyncResponse, (k, v) -> true));
    }
}
 
Example #4
Source File: KafkaStorageHttpService.java    From zipkin-storage-kafka with Apache License 2.0 6 votes vote down vote up
@Get("/autocompleteTags/:key")
@ProducesJson
public JsonNode getAutocompleteValues(@Param("key") String key) {
  try {
    if (!storage.traceSearchEnabled) return MAPPER.createArrayNode();
    ReadOnlyKeyValueStore<String, Set<String>> autocompleteTagsStore =
        storage.getTraceStorageStream().store(AUTOCOMPLETE_TAGS_STORE_NAME,
            QueryableStoreTypes.keyValueStore());
    Set<String> values = autocompleteTagsStore.get(key);
    ArrayNode array = MAPPER.createArrayNode();
    if (values != null) values.forEach(array::add);
    return array;
  } catch (InvalidStateStoreException e) {
    LOG.debug("State store is not ready", e);
    throw e;
  }
}
 
Example #5
Source File: KafkaStorageHttpService.java    From zipkin-storage-kafka with Apache License 2.0 6 votes vote down vote up
@Get("/autocompleteTags")
@ProducesJson
public JsonNode getAutocompleteTags() {
  try {
    if (!storage.traceSearchEnabled) return MAPPER.createArrayNode();
    ReadOnlyKeyValueStore<String, Set<String>> autocompleteTagsStore =
        storage.getTraceStorageStream().store(AUTOCOMPLETE_TAGS_STORE_NAME,
            QueryableStoreTypes.keyValueStore());
    ArrayNode array = MAPPER.createArrayNode();
    try (KeyValueIterator<String, Set<String>> all = autocompleteTagsStore.all()) {
      all.forEachRemaining(keyValue -> array.add(keyValue.key));
    }
    return array;
  } catch (InvalidStateStoreException e) {
    LOG.debug("State store is not ready", e);
    throw e;
  }
}
 
Example #6
Source File: KafkaStorageHttpService.java    From zipkin-storage-kafka with Apache License 2.0 6 votes vote down vote up
@Get("/traceMany")
public AggregatedHttpResponse getTraces(@Param("traceIds") String traceIds) {
  try {
    if (!storage.traceByIdQueryEnabled) return AggregatedHttpResponse.of(HttpStatus.NOT_FOUND);
    ReadOnlyKeyValueStore<String, List<Span>> store = storage.getTraceStorageStream()
        .store(TRACES_STORE_NAME, QueryableStoreTypes.keyValueStore());
    List<List<Span>> result = new ArrayList<>();
    for (String traceId : traceIds.split(",", 1000)) {
      result.add(store.get(traceId));
    }
    return AggregatedHttpResponse.of(HttpStatus.OK, MediaType.JSON, writeTraces(result));
  } catch (InvalidStateStoreException e) {
    LOG.debug("State store is not ready", e);
    return AggregatedHttpResponse.of(HttpStatus.SERVICE_UNAVAILABLE);
  }
}
 
Example #7
Source File: KafkaStorageHttpService.java    From zipkin-storage-kafka with Apache License 2.0 6 votes vote down vote up
@Get("/traces/:trace_id")
public AggregatedHttpResponse getTrace(@Param("trace_id") String traceId) {
  try {
    if (!storage.traceByIdQueryEnabled) return AggregatedHttpResponse.of(HttpStatus.NOT_FOUND);
    ReadOnlyKeyValueStore<String, List<Span>> store =
        storage.getTraceStorageStream()
            .store(TRACES_STORE_NAME, QueryableStoreTypes.keyValueStore());
    List<Span> spans = store.get(traceId);
    return AggregatedHttpResponse.of(
        HttpStatus.OK,
        MediaType.JSON,
        SpanBytesEncoder.JSON_V2.encodeList(spans));
  } catch (InvalidStateStoreException e) {
    LOG.debug("State store is not ready", e);
    return AggregatedHttpResponse.of(HttpStatus.SERVICE_UNAVAILABLE);
  }
}
 
Example #8
Source File: KafkaStorageHttpService.java    From zipkin-storage-kafka with Apache License 2.0 6 votes vote down vote up
@Get("/serviceNames/:service_name/remoteServiceNames")
@ProducesJson
public JsonNode getRemoteServiceNames(@Param("service_name") String serviceName) {
  try {
    if (!storage.traceSearchEnabled) return MAPPER.createArrayNode();
    ReadOnlyKeyValueStore<String, Set<String>> store = storage.getTraceStorageStream()
        .store(REMOTE_SERVICE_NAMES_STORE_NAME, QueryableStoreTypes.keyValueStore());
    Set<String> names = store.get(serviceName);
    ArrayNode array = MAPPER.createArrayNode();
    if (names != null) names.forEach(array::add);
    return (array);
  } catch (InvalidStateStoreException e) {
    LOG.debug("State store is not ready", e);
    throw e;
  }
}
 
Example #9
Source File: KafkaStorageHttpService.java    From zipkin-storage-kafka with Apache License 2.0 6 votes vote down vote up
@Get("/serviceNames/:service_name/spanNames")
@ProducesJson
public JsonNode getSpanNames(@Param("service_name") String serviceName) {
  try {
    if (!storage.traceSearchEnabled) return MAPPER.createArrayNode();
    ReadOnlyKeyValueStore<String, Set<String>> store = storage.getTraceStorageStream()
        .store(SPAN_NAMES_STORE_NAME, QueryableStoreTypes.keyValueStore());
    Set<String> names = store.get(serviceName);
    ArrayNode array = MAPPER.createArrayNode();
    if (names != null) names.forEach(array::add);
    return array;
  } catch (InvalidStateStoreException e) {
    LOG.debug("State store is not ready", e);
    throw e;
  }
}
 
Example #10
Source File: KafkaStorageHttpService.java    From zipkin-storage-kafka with Apache License 2.0 6 votes vote down vote up
@Get("/serviceNames")
@ProducesJson
public JsonNode getServiceNames() {
  try {
    if (!storage.traceSearchEnabled) return MAPPER.createArrayNode();
    ReadOnlyKeyValueStore<String, String> store = storage.getTraceStorageStream()
        .store(SERVICE_NAMES_STORE_NAME, QueryableStoreTypes.keyValueStore());
    ArrayNode array = MAPPER.createArrayNode();
    try (KeyValueIterator<String, String> all = store.all()) {
      all.forEachRemaining(keyValue -> array.add(keyValue.value));
    }
    return array;
  } catch (InvalidStateStoreException e) {
    LOG.debug("State store is not ready", e);
    throw e;
  }
}
 
Example #11
Source File: DistributedService.java    From apicurio-registry with Apache License 2.0 6 votes vote down vote up
protected final Collection<S> allServicesForStore() {
    Collection<StreamsMetadata> smetas = streams.allMetadataForStore(storeName);
    if (smetas.isEmpty()) {
        throw new InvalidStateStoreException(
            "StreamsMetadata is currently unavailable. " +
            "This can occur during rebalance operations. " +
            "Store-name: " + storeName
        );
    }
    ArrayList<S> services = new ArrayList<>(smetas.size());
    for (StreamsMetadata smeta : smetas) {
        // only use stores that have some active partitions
        if (smeta.topicPartitions().size() > 0) {
            services.add(serviceForHostInfo(smeta.hostInfo()));
        }
    }
    return services;
}
 
Example #12
Source File: InteractiveQueries.java    From quarkus-quickstarts with Apache License 2.0 5 votes vote down vote up
private ReadOnlyKeyValueStore<Integer, Aggregation> getWeatherStationStore() {
    while (true) {
        try {
            return streams.store(TopologyProducer.WEATHER_STATIONS_STORE, QueryableStoreTypes.keyValueStore());
        } catch (InvalidStateStoreException e) {
            // ignore, store not ready yet
        }
    }
}
 
Example #13
Source File: KafkaStreamsEndpoint.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private ReadOnlyKeyValueStore<Integer, Long> getCountstore() {
    while (true) {
        try {
            return streams.store("countstore", QueryableStoreTypes.keyValueStore());
        } catch (InvalidStateStoreException e) {
            // ignore, store not ready yet
        }
    }
}
 
Example #14
Source File: OrderService.java    From qcon-microservices with Apache License 2.0 5 votes vote down vote up
/**
 * Perform a "Long-Poll" styled get. This method will attempt to get the order for the ID
 * blocking until the order has been validated or passed timeout is reached. Non-blocking IO is used to
 * implement this, but the API will block the calling thread if no data is available
 *
 * @param id - the key of the value to retrieve
 * @param timeout - the timeout for the long-poll
 * @param asyncResponse - async response used to trigger the poll early should the appropriate
 * value become available
 */
@GET
@ManagedAsync
@Path("orders/{id}/validated")
@Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN})
public void getPostValidationWithTimeout(@PathParam("id") final String id,
                                         @QueryParam("timeout") @DefaultValue(CALL_TIMEOUT) Long timeout,
                                         @Suspended final AsyncResponse asyncResponse) {
    setTimeout(timeout, asyncResponse);

    log.info("running GET on this node");
    try {
        Order order = ordersStore().get(id);
        if (order == null || (order.getState() != OrderState.VALIDATED && order.getState() != OrderState.FAILED)) {
            log.info("Delaying get as a validated order not present for id " + id);
            outstandingRequests.put(id, new FilteredResponse<>(asyncResponse,
                    (k, v) -> (v.getState() == OrderState.VALIDATED || v.getState() == OrderState.FAILED)));
        } else {
            asyncResponse.resume(order);
        }
    } catch (InvalidStateStoreException e) {
        //Store not ready so delay
        log.info("Delaying request for " + id + " because state store is not ready.");
        outstandingRequests.put(id, new FilteredResponse<>(asyncResponse,
                (k, v) -> (v.getState() == OrderState.VALIDATED || v.getState() == OrderState.FAILED)));
    }
}
 
Example #15
Source File: InteractiveQueryService.java    From micronaut-kafka with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve and return a queryable store by name created in the application.  If state store is not
 * present an Optional.empty() will be returned.
 *
 * @param storeName name of the queryable store
 * @param storeType type of the queryable store
 * @param <T>       generic queryable store
 * @return queryable store.
 */
public <T> Optional<T> getQueryableStore(String storeName, QueryableStoreType<T> storeType) {
    for (KafkaStreams kafkaStream : this.streams) {
        try {
            T store = kafkaStream.store(storeName, storeType);
            if (store != null) {
                return Optional.of(store);
            }
        } catch (InvalidStateStoreException ignored) {
            //pass through
        }
    }
    return Optional.empty();
}
 
Example #16
Source File: KafkaStorageHttpService.java    From zipkin-storage-kafka with Apache License 2.0 5 votes vote down vote up
@Get("/dependencies")
public AggregatedHttpResponse getDependencies(
    @Param("endTs") long endTs,
    @Param("lookback") long lookback
) {
  try {
    if (!storage.dependencyQueryEnabled) return AggregatedHttpResponse.of(HttpStatus.NOT_FOUND);
    ReadOnlyWindowStore<Long, DependencyLink> store =
        storage.getDependencyStorageStream()
            .store(DEPENDENCIES_STORE_NAME, QueryableStoreTypes.windowStore());
    List<DependencyLink> links = new ArrayList<>();
    Instant from = Instant.ofEpochMilli(endTs - lookback);
    Instant to = Instant.ofEpochMilli(endTs);
    try (KeyValueIterator<Windowed<Long>, DependencyLink> iterator = store.fetchAll(from, to)) {
      iterator.forEachRemaining(keyValue -> links.add(keyValue.value));
    }
    List<DependencyLink> mergedLinks = DependencyLinker.merge(links);
    LOG.debug("Dependencies found from={}-to={}: {}", from, to, mergedLinks.size());
    return AggregatedHttpResponse.of(
        HttpStatus.OK,
        MediaType.JSON,
        DependencyLinkBytesEncoder.JSON_V1.encodeList(mergedLinks));
  } catch (InvalidStateStoreException e) {
    LOG.debug("State store is not ready", e);
    return AggregatedHttpResponse.of(HttpStatus.SERVICE_UNAVAILABLE);
  }
}
 
Example #17
Source File: StreamsRegistryConfiguration.java    From apicurio-registry with Apache License 2.0 4 votes vote down vote up
@Produces
@ApplicationScoped
public Lifecycle storageGrpcServer(
    HostInfo storageLocalHost,
    KeyValueStoreGrpc.KeyValueStoreImplBase storageStoreGrpcImpl,
    AsyncBiFunctionServiceGrpc.AsyncBiFunctionServiceImplBase storageAsyncBiFunctionServiceGrpcImpl
) {

    UnknownStatusDescriptionInterceptor unknownStatusDescriptionInterceptor =
        new UnknownStatusDescriptionInterceptor(
            ImmutableMap.of(
                IllegalArgumentException.class, Status.INVALID_ARGUMENT,
                IllegalStateException.class, Status.FAILED_PRECONDITION,
                InvalidStateStoreException.class, Status.FAILED_PRECONDITION,
                Throwable.class, Status.INTERNAL
            )
        );

    Server server = ServerBuilder
        .forPort(storageLocalHost.port())
        .addService(
            ServerInterceptors.intercept(
                storageStoreGrpcImpl,
                unknownStatusDescriptionInterceptor
            )
        )
        .addService(
            ServerInterceptors.intercept(
                storageAsyncBiFunctionServiceGrpcImpl,
                unknownStatusDescriptionInterceptor
            )
        )
        .build();

    return new Lifecycle() {
        @Override
        public void start() {
            try {
                server.start();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        @Override
        public void stop() {
            ConcurrentUtil
                .<Server>consumer(Server::awaitTermination)
                .accept(server.shutdown());
        }

        @Override
        public boolean isRunning() {
            return !(server.isShutdown() || server.isTerminated());
        }
    };
}
 
Example #18
Source File: KafkaStorageHttpService.java    From zipkin-storage-kafka with Apache License 2.0 4 votes vote down vote up
@Get("/traces")
public AggregatedHttpResponse getTraces(
    @Param("serviceName") Optional<String> serviceName,
    @Param("remoteServiceName") Optional<String> remoteServiceName,
    @Param("spanName") Optional<String> spanName,
    @Param("annotationQuery") Optional<String> annotationQuery,
    @Param("minDuration") Optional<Long> minDuration,
    @Param("maxDuration") Optional<Long> maxDuration,
    @Param("endTs") Optional<Long> endTs,
    @Default("86400000") @Param("lookback") Long lookback,
    @Default("10") @Param("limit") int limit
) {
  try {
    if (!storage.traceSearchEnabled) return AggregatedHttpResponse.of(HttpStatus.NOT_FOUND);
    QueryRequest request =
        QueryRequest.newBuilder()
            .serviceName(serviceName.orElse(null))
            .remoteServiceName(remoteServiceName.orElse(null))
            .spanName(spanName.orElse(null))
            .parseAnnotationQuery(annotationQuery.orElse(null))
            .minDuration(minDuration.orElse(null))
            .maxDuration(maxDuration.orElse(null))
            .endTs(endTs.orElse(System.currentTimeMillis()))
            .lookback(lookback)
            .limit(limit)
            .build();
    ReadOnlyKeyValueStore<String, List<Span>> tracesStore =
        storage.getTraceStorageStream()
            .store(TRACES_STORE_NAME, QueryableStoreTypes.keyValueStore());
    ReadOnlyKeyValueStore<Long, Set<String>> traceIdsByTsStore =
        storage.getTraceStorageStream()
            .store(SPAN_IDS_BY_TS_STORE_NAME, QueryableStoreTypes.keyValueStore());
    List<List<Span>> traces = new ArrayList<>();
    List<String> traceIds = new ArrayList<>();
    long from = MILLISECONDS.toMicros(request.endTs() - request.lookback());
    long to = MILLISECONDS.toMicros(request.endTs());
    long bucket = SECONDS.toMicros(30);
    long checkpoint = to - bucket; // 30 sec before upper bound
    if (checkpoint <= from ||
        tracesStore.approximateNumEntries() <= minTracesStored) { // do one run
      try (KeyValueIterator<Long, Set<String>> spanIds = traceIdsByTsStore.range(from, to)) {
        addResults(request, tracesStore, traces, traceIds, spanIds);
      }
    } else {
      while (checkpoint > from && traces.size() < request.limit()) {
        try (KeyValueIterator<Long, Set<String>> spanIds =
                 traceIdsByTsStore.range(checkpoint, to)) {
          addResults(request, tracesStore, traces, traceIds, spanIds);
        }
        to = checkpoint;
        checkpoint = checkpoint - bucket; // 1 min before more
      }
    }
    traces.sort(Comparator.<List<Span>>comparingLong(o -> o.get(0).timestampAsLong()).reversed());
    LOG.debug("Traces found from query {}: {}", request, traces.size());
    List<List<Span>> result = traces.stream().limit(request.limit()).collect(Collectors.toList());
    return AggregatedHttpResponse.of(HttpStatus.OK, MediaType.JSON,
        writeTraces(result));
  } catch (InvalidStateStoreException e) {
    LOG.debug("State store is not ready", e);
    return AggregatedHttpResponse.of(HttpStatus.SERVICE_UNAVAILABLE);
  }
}
 
Example #19
Source File: WindowQueryVerticleTest.java    From kiqr with Apache License 2.0 4 votes vote down vote up
@Test
public void illegalStateStoreExceptionOnQuery(TestContext context){
    KafkaStreams streamMock = mock(KafkaStreams.class);
    ReadOnlyWindowStore<Object, Object> storeMock = mock(ReadOnlyWindowStore.class);
    when(streamMock.store(eq("store"), any(QueryableStoreType.class))).thenReturn(storeMock);
    when(storeMock.fetch(any(), anyLong(), anyLong())).thenThrow(InvalidStateStoreException.class);

    rule.vertx().deployVerticle(new WindowedQueryVerticle("host", streamMock), context.asyncAssertSuccess(deployment->{

        WindowedQuery query = new WindowedQuery("store", Serdes.String().getClass().getName(), "key".getBytes(),  Serdes.String().getClass().getName(), 0, 1);

        rule.vertx().eventBus().send(Config.WINDOWED_QUERY_ADDRESS_PREFIX + "host", query, context.asyncAssertFailure(handler ->{

            context.assertTrue(handler instanceof ReplyException);
            ReplyException ex = (ReplyException) handler;
            context.assertEquals(500, ex.failureCode());

        }));

    }));

}
 
Example #20
Source File: WindowQueryVerticleTest.java    From kiqr with Apache License 2.0 4 votes vote down vote up
@Test
public void illegalStateStoreExceptionOnStoreInitialization(TestContext context){
    KafkaStreams streamMock = mock(KafkaStreams.class);

    when(streamMock.store(eq("store"), any(QueryableStoreType.class) )).thenThrow( InvalidStateStoreException.class);

    rule.vertx().deployVerticle(new WindowedQueryVerticle("host", streamMock), context.asyncAssertSuccess(deployment->{

        WindowedQuery query = new WindowedQuery("store", Serdes.String().getClass().getName(), "key".getBytes(),  Serdes.String().getClass().getName(), 0, 1);

        rule.vertx().eventBus().send(Config.WINDOWED_QUERY_ADDRESS_PREFIX + "host", query, context.asyncAssertFailure(handler ->{

            context.assertTrue(handler instanceof ReplyException);
            ReplyException ex = (ReplyException) handler;
            context.assertEquals(500, ex.failureCode());

        }));

    }));

}
 
Example #21
Source File: ScalarKeyValueQueryVerticleTest.java    From kiqr with Apache License 2.0 4 votes vote down vote up
@Test
public void illegalStateStoreExceptionOnQuery(TestContext context){

    KafkaStreams streamMock = mock(KafkaStreams.class);

    ReadOnlyKeyValueStore<Object, Object> storeMock = mock(ReadOnlyKeyValueStore.class);

    when(streamMock.store(eq("store"), any(QueryableStoreType.class))).thenReturn(storeMock);
    when(storeMock.get(any())).thenThrow(InvalidStateStoreException.class);
    rule.vertx().deployVerticle(new ScalarKeyValueQueryVerticle("host", streamMock), context.asyncAssertSuccess(deployment->{

        KeyBasedQuery query = new KeyBasedQuery("store", Serdes.String().getClass().getName(), "key".getBytes(), Serdes.String().getClass().getName());

        rule.vertx().eventBus().send(Config.KEY_VALUE_QUERY_ADDRESS_PREFIX + "host", query, context.asyncAssertFailure(handler ->{

            context.assertTrue(handler instanceof ReplyException);
            ReplyException ex = (ReplyException) handler;
            context.assertEquals(500, ex.failureCode());

        }));


    }));

}
 
Example #22
Source File: ScalarKeyValueQueryVerticleTest.java    From kiqr with Apache License 2.0 4 votes vote down vote up
@Test
public void illegalStateStoreExceptionOnStoreInitialization(TestContext context){
    KafkaStreams streamMock = mock(KafkaStreams.class);

    when(streamMock.store(eq("store"), any(QueryableStoreType.class))).thenThrow(InvalidStateStoreException.class);


    rule.vertx().deployVerticle(new ScalarKeyValueQueryVerticle("host", streamMock), context.asyncAssertSuccess(deployment->{

        KeyBasedQuery query = new KeyBasedQuery("store", Serdes.String().getClass().getName(), "key".getBytes(), Serdes.String().getClass().getName());

        rule.vertx().eventBus().send(Config.KEY_VALUE_QUERY_ADDRESS_PREFIX + "host", query, context.asyncAssertFailure(handler ->{

            context.assertTrue(handler instanceof ReplyException);
            ReplyException ex = (ReplyException) handler;
            context.assertEquals(500, ex.failureCode());

        }));


    }));

}
 
Example #23
Source File: KeyValueCountVerticleTest.java    From kiqr with Apache License 2.0 4 votes vote down vote up
@Test
public void illegalStateStoreExceptionOnQuery(TestContext context){
    KafkaStreams streamMock = mock(KafkaStreams.class);
    ReadOnlyKeyValueStore<Object, Object> storeMock = mock(ReadOnlyKeyValueStore.class);
    KeyValueIterator<Object, Object> iteratorMock = mock(KeyValueIterator.class);

    when(streamMock.store(eq("store"), any(QueryableStoreType.class))).thenReturn(storeMock);
    when(storeMock.approximateNumEntries()).thenThrow(InvalidStateStoreException.class);

    rule.vertx().deployVerticle(new KeyValueCountVerticle("host", streamMock), context.asyncAssertSuccess(deployment->{

        KeyValueStoreCountQuery query = new KeyValueStoreCountQuery("store");

        rule.vertx().eventBus().send(Config.COUNT_KEY_VALUE_QUERY_ADDRESS_PREFIX + "host", query, context.asyncAssertFailure(handler ->{

            context.assertTrue(handler instanceof ReplyException);
            ReplyException ex = (ReplyException) handler;
            context.assertEquals(500, ex.failureCode());

        }));

    }));

}
 
Example #24
Source File: RangeKeyValuesQueryVerticleTest.java    From kiqr with Apache License 2.0 4 votes vote down vote up
@Test
public void illegalStateStoreExceptionOnQuery(TestContext context){
    KafkaStreams streamMock = mock(KafkaStreams.class);
    ReadOnlyKeyValueStore<Object, Object> storeMock = mock(ReadOnlyKeyValueStore.class);
    when(streamMock.store(eq("store"), any(QueryableStoreType.class))).thenReturn(storeMock);
    when(storeMock.range(any(), any())).thenThrow(InvalidStateStoreException.class);

    rule.vertx().deployVerticle(new RangeKeyValueQueryVerticle("host", streamMock), context.asyncAssertSuccess(deployment->{

        RangeKeyValueQuery query = new RangeKeyValueQuery("store", Serdes.String().getClass().getName(), Serdes.String().getClass().getName(), "key".getBytes(), "key".getBytes());

        rule.vertx().eventBus().send(Config.RANGE_KEY_VALUE_QUERY_ADDRESS_PREFIX + "host", query, context.asyncAssertFailure(handler ->{

            context.assertTrue(handler instanceof ReplyException);
            ReplyException ex = (ReplyException) handler;
            context.assertEquals(500, ex.failureCode());

        }));

    }));

}
 
Example #25
Source File: RangeKeyValuesQueryVerticleTest.java    From kiqr with Apache License 2.0 4 votes vote down vote up
@Test
public void illegalStateStoreExceptionOnStoreInitialization(TestContext context){
    KafkaStreams streamMock = mock(KafkaStreams.class);

    when(streamMock.store(eq("store"), any(QueryableStoreType.class) )).thenThrow( InvalidStateStoreException.class);

    rule.vertx().deployVerticle(new RangeKeyValueQueryVerticle("host", streamMock), context.asyncAssertSuccess(deployment->{

        RangeKeyValueQuery query = new RangeKeyValueQuery("store", Serdes.String().getClass().getName(), Serdes.String().getClass().getName(), "key".getBytes(), "key".getBytes());

        rule.vertx().eventBus().send(Config.RANGE_KEY_VALUE_QUERY_ADDRESS_PREFIX + "host", query, context.asyncAssertFailure(handler ->{

            context.assertTrue(handler instanceof ReplyException);
            ReplyException ex = (ReplyException) handler;
            context.assertEquals(500, ex.failureCode());

        }));

    }));

}
 
Example #26
Source File: AllKeyValuesQueryVerticleTest.java    From kiqr with Apache License 2.0 4 votes vote down vote up
@Test
public void illegalStateStoreExceptionOnQuery(TestContext context){
    KafkaStreams streamMock = mock(KafkaStreams.class);
    ReadOnlyKeyValueStore<Object, Object> storeMock = mock(ReadOnlyKeyValueStore.class);
    when(streamMock.store(eq("store"), any(QueryableStoreType.class))).thenReturn(storeMock);
    when(storeMock.all()).thenThrow(InvalidStateStoreException.class);

    rule.vertx().deployVerticle(new AllKeyValuesQueryVerticle("host", streamMock), context.asyncAssertSuccess(deployment->{

        StoreWideQuery query = new StoreWideQuery("store", Serdes.String().getClass().getName(), Serdes.String().getClass().getName());

        rule.vertx().eventBus().send(Config.ALL_KEY_VALUE_QUERY_ADDRESS_PREFIX + "host", query, context.asyncAssertFailure(handler ->{

            context.assertTrue(handler instanceof ReplyException);
            ReplyException ex = (ReplyException) handler;
            context.assertEquals(500, ex.failureCode());

        }));

    }));

}
 
Example #27
Source File: AllKeyValuesQueryVerticleTest.java    From kiqr with Apache License 2.0 4 votes vote down vote up
@Test
public void illegalStateStoreExceptionOnStoreInitialization(TestContext context){
    KafkaStreams streamMock = mock(KafkaStreams.class);

    when(streamMock.store(eq("store"), any(QueryableStoreType.class) )).thenThrow( InvalidStateStoreException.class);

    rule.vertx().deployVerticle(new AllKeyValuesQueryVerticle("host", streamMock), context.asyncAssertSuccess(deployment->{

        StoreWideQuery query = new StoreWideQuery("store", Serdes.String().getClass().getName(), Serdes.String().getClass().getName());

        rule.vertx().eventBus().send(Config.ALL_KEY_VALUE_QUERY_ADDRESS_PREFIX + "host", query, context.asyncAssertFailure(handler ->{

            context.assertTrue(handler instanceof ReplyException);
            ReplyException ex = (ReplyException) handler;
            context.assertEquals(500, ex.failureCode());

        }));

    }));

}
 
Example #28
Source File: SessionWindowQueryVerticleTest.java    From kiqr with Apache License 2.0 4 votes vote down vote up
@Test
public void illegalStateStoreExceptionOnQuery(TestContext context){
    KafkaStreams streamMock = mock(KafkaStreams.class);
    ReadOnlySessionStore<Object, Object> storeMock = mock(ReadOnlySessionStore.class);
    when(streamMock.store(eq("store"), any(QueryableStoreType.class))).thenReturn(storeMock);
    when(storeMock.fetch(any())).thenThrow(InvalidStateStoreException.class);

    rule.vertx().deployVerticle(new SessionWindowQueryVerticle("host", streamMock), context.asyncAssertSuccess(deployment->{

        KeyBasedQuery query = new KeyBasedQuery("store", Serdes.String().getClass().getName(), "key".getBytes(),  Serdes.String().getClass().getName());

        rule.vertx().eventBus().send(Config.SESSION_QUERY_ADDRESS_PREFIX + "host", query, context.asyncAssertFailure(handler ->{

            context.assertTrue(handler instanceof ReplyException);
            ReplyException ex = (ReplyException) handler;
            context.assertEquals(500, ex.failureCode());

        }));

    }));

}
 
Example #29
Source File: SessionWindowQueryVerticleTest.java    From kiqr with Apache License 2.0 4 votes vote down vote up
@Test
public void illegalStateStoreExceptionOnStoreInitialization(TestContext context){
    KafkaStreams streamMock = mock(KafkaStreams.class);

    when(streamMock.store(eq("store"), any(QueryableStoreType.class) )).thenThrow( InvalidStateStoreException.class);

    rule.vertx().deployVerticle(new SessionWindowQueryVerticle("host", streamMock), context.asyncAssertSuccess(deployment->{

        KeyBasedQuery query = new KeyBasedQuery("store", Serdes.String().getClass().getName(), "key".getBytes(),  Serdes.String().getClass().getName());

        rule.vertx().eventBus().send(Config.SESSION_QUERY_ADDRESS_PREFIX + "host", query, context.asyncAssertFailure(handler ->{

            context.assertTrue(handler instanceof ReplyException);
            ReplyException ex = (ReplyException) handler;
            context.assertEquals(500, ex.failureCode());

        }));

    }));

}
 
Example #30
Source File: KafkaBoardClient.java    From event-store-demo with GNU General Public License v3.0 3 votes vote down vote up
@Override
    public Board find( final UUID boardUuid ) {
        log.debug( "find : enter" );

//        while( true ) {

            try {

                ReadOnlyKeyValueStore<String, Board> store = queryableStoreRegistry.getQueryableStoreType( BOARD_EVENTS_SNAPSHOTS, QueryableStoreTypes.<String, Board>keyValueStore() );

                Board board = store.get( boardUuid.toString() );
                if( null != board ) {

                    board.flushChanges();
                    log.debug( "find : board=" + board.toString() );

                    log.debug( "find : exit" );
                    return board;

                } else {

                    throw new IllegalArgumentException( "board[" + boardUuid.toString() + "] not found!" );
                }

            } catch( InvalidStateStoreException e ) {
                log.error( "find : error", e );

//                try {
//                    Thread.sleep( 100 );
//                } catch( InterruptedException e1 ) {
//                    log.error( "find : thread interrupted", e1 );
//                }

            }

//        }

        throw new IllegalArgumentException( "board[" + boardUuid.toString() + "] not found!" );
    }