org.apache.kafka.streams.state.QueryableStoreType Java Examples

The following examples show how to use org.apache.kafka.streams.state.QueryableStoreType. 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: KafkaStreamsInteractiveQueryIntegrationTests.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 6 votes vote down vote up
@Test
public void testStateStoreRetrievalRetry() {

	StreamsBuilderFactoryBean mock = Mockito.mock(StreamsBuilderFactoryBean.class);
	KafkaStreams mockKafkaStreams = Mockito.mock(KafkaStreams.class);
	Mockito.when(mock.getKafkaStreams()).thenReturn(mockKafkaStreams);
	KafkaStreamsRegistry kafkaStreamsRegistry = new KafkaStreamsRegistry();
	kafkaStreamsRegistry.registerKafkaStreams(mock);
	KafkaStreamsBinderConfigurationProperties binderConfigurationProperties =
			new KafkaStreamsBinderConfigurationProperties(new KafkaProperties());
	binderConfigurationProperties.getStateStoreRetry().setMaxAttempts(3);
	InteractiveQueryService interactiveQueryService = new InteractiveQueryService(kafkaStreamsRegistry,
			binderConfigurationProperties);

	QueryableStoreType<ReadOnlyKeyValueStore<Object, Object>> storeType = QueryableStoreTypes.keyValueStore();
	try {
		interactiveQueryService.getQueryableStore("foo", storeType);
	}
	catch (Exception ignored) {

	}

	Mockito.verify(mockKafkaStreams, times(3)).store("foo", storeType);
}
 
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: RangeKeyValuesQueryVerticleTest.java    From kiqr with Apache License 2.0 6 votes vote down vote up
@Test
public void notFoundWithNoResult(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);
    SimpleKeyValueIterator iterator = new SimpleKeyValueIterator();
    when(storeMock.range(any(), any())).thenReturn(iterator);


    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.asyncAssertSuccess(reply ->{

            context.assertTrue(reply.body() instanceof MultiValuedKeyValueQueryResponse);
            MultiValuedKeyValueQueryResponse response = (MultiValuedKeyValueQueryResponse) reply.body();
            context.assertEquals(0, response.getResults().size());
            context.assertTrue(iterator.closed);

        }));

    }));

}
 
Example #4
Source File: AllKeyValuesQueryVerticleTest.java    From kiqr with Apache License 2.0 6 votes vote down vote up
@Test
public void notFoundWithNoResult(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);
    SimpleKeyValueIterator iterator = new SimpleKeyValueIterator();
    when(storeMock.all()).thenReturn(iterator);


    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.asyncAssertSuccess(reply ->{

            context.assertTrue(reply.body() instanceof MultiValuedKeyValueQueryResponse);
            MultiValuedKeyValueQueryResponse response = (MultiValuedKeyValueQueryResponse) reply.body();
            context.assertEquals(0, response.getResults().size());
            context.assertTrue(iterator.closed);

        }));

    }));

}
 
Example #5
Source File: DistributedReadOnlyKeyValueStore.java    From apicurio-registry with Apache License 2.0 5 votes vote down vote up
@Override
protected ExtReadOnlyKeyValueStore<K, V> localService(String storeName, KafkaStreams streams) {
    QueryableStoreType<ReadOnlyKeyValueStore<K, V>> queryableStoreType = QueryableStoreTypes.keyValueStore();
    StoreQueryParameters<ReadOnlyKeyValueStore<K, V>> sqp = StoreQueryParameters.fromNameAndType(storeName, queryableStoreType);
    ReadOnlyKeyValueStore<K, V> delegate = streams.store(sqp);
    return new ExtReadOnlyKeyValueStoreImpl<>(delegate, filterPredicate);
}
 
Example #6
Source File: KeyValueStoreGrpcImplLocalDispatcher.java    From apicurio-registry with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
private <K, V> ExtReadOnlyKeyValueStore<K, V> keyValueStore(String storeName) {
    return (ExtReadOnlyKeyValueStore<K, V>)
        keyValueStores.computeIfAbsent(
                storeName,
                sn -> {
                    QueryableStoreType<ReadOnlyKeyValueStore<K, V>> queryableStoreType = QueryableStoreTypes.keyValueStore();
                    StoreQueryParameters<ReadOnlyKeyValueStore<K, V>> sqp = StoreQueryParameters.fromNameAndType(storeName, queryableStoreType);
                    return new ExtReadOnlyKeyValueStoreImpl(
                            streams.store(sqp),
                            filterPredicate
                    );
                }
        );
}
 
Example #7
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 #8
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 #9
Source File: WindowQueryVerticleTest.java    From kiqr with Apache License 2.0 4 votes vote down vote up
@Test
public void unexpectedExceptionOnQuery(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(IllegalArgumentException.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 #10
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 #11
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 #12
Source File: ScalarKeyValueQueryVerticleTest.java    From kiqr with Apache License 2.0 4 votes vote down vote up
@Test
public void invalidValueSerde(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(IllegalArgumentException.class);
    rule.vertx().deployVerticle(new ScalarKeyValueQueryVerticle("host", streamMock), context.asyncAssertSuccess(deployment->{

        KeyBasedQuery query = new KeyBasedQuery("store", Serdes.String().getClass().getName(), "key".getBytes(), "i am not a serde");

        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(400, ex.failureCode());

        }));


    }));

}
 
Example #13
Source File: ScalarKeyValueQueryVerticleTest.java    From kiqr with Apache License 2.0 4 votes vote down vote up
@Test
public void invalidKeySerde(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(IllegalArgumentException.class);
    rule.vertx().deployVerticle(new ScalarKeyValueQueryVerticle("host", streamMock), context.asyncAssertSuccess(deployment->{

        KeyBasedQuery query = new KeyBasedQuery("store", "i am not a serde", "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(400, ex.failureCode());

        }));


    }));

}
 
Example #14
Source File: ScalarKeyValueQueryVerticleTest.java    From kiqr with Apache License 2.0 4 votes vote down vote up
@Test
public void unexpectedRuntimeException(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(IllegalArgumentException.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 #15
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 #16
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 #17
Source File: KeyValueCountVerticleTest.java    From kiqr with Apache License 2.0 4 votes vote down vote up
@Test
public void unexpectedExceptionOnQuery(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(IllegalArgumentException.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 #18
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 #19
Source File: KeyValueCountVerticleTest.java    From kiqr with Apache License 2.0 4 votes vote down vote up
@Test
public void success(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()).thenReturn(42L);


    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.asyncAssertSuccess(reply ->{

            context.assertTrue(reply.body() instanceof Long);
            context.assertEquals(42L, reply.body());

        }));


    }));


}
 
Example #20
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 #21
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 #22
Source File: SessionWindowQueryVerticleTest.java    From kiqr with Apache License 2.0 4 votes vote down vote up
@Test
public void unexpectedExceptionOnQuery(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(IllegalArgumentException.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 #23
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 #24
Source File: RangeKeyValuesQueryVerticleTest.java    From kiqr with Apache License 2.0 4 votes vote down vote up
@Test
public void unexpectedExceptionOnQuery(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(IllegalArgumentException.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: AllKeyValuesQueryVerticleTest.java    From kiqr with Apache License 2.0 4 votes vote down vote up
@Test
public void unexpectedExceptionOnQuery(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(IllegalArgumentException.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 #26
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 #27
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 #28
Source File: RangeKeyValuesQueryVerticleTest.java    From kiqr with Apache License 2.0 3 votes vote down vote up
@Test
public void successWithDoubleResult(TestContext context){
    KafkaStreams streamMock = mock(KafkaStreams.class);
    ReadOnlyKeyValueStore<Object, Object> storeMock = mock(ReadOnlyKeyValueStore.class);
    when(streamMock.store(eq("store"), any(QueryableStoreType.class))).thenReturn(storeMock);

    SimpleKeyValueIterator iterator = new SimpleKeyValueIterator(new KeyValue<Object, Object>("key", "value"), new KeyValue<Object, Object>("key2", "value2"));
    when(storeMock.range(any(), any())).thenReturn(iterator);


    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.asyncAssertSuccess(reply ->{

            context.assertTrue(reply.body() instanceof MultiValuedKeyValueQueryResponse);
            MultiValuedKeyValueQueryResponse response = (MultiValuedKeyValueQueryResponse) reply.body();
            context.assertEquals(2, response.getResults().size());
            context.assertTrue(response.getResults().containsKey("a2V5"));//"key" as UT8/b64
            context.assertEquals("dmFsdWU=", response.getResults().get("a2V5"));//"value" as UT8/b64

            context.assertTrue(response.getResults().containsKey("a2V5Mg=="));//"key2" as UT8/b64
            context.assertEquals("dmFsdWUy", response.getResults().get("a2V5Mg=="));//"value" as UT8/b64

            context.assertTrue(iterator.closed);

        }));

    }));

}
 
Example #29
Source File: RangeKeyValuesQueryVerticleTest.java    From kiqr with Apache License 2.0 3 votes vote down vote up
@Test
public void successWithSingleResult(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);
    SimpleKeyValueIterator iterator = new SimpleKeyValueIterator(new KeyValue<Object, Object>("key", "value"));

    when(storeMock.range(any(), any())).thenReturn(iterator);


    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.asyncAssertSuccess(reply ->{

            context.assertTrue(reply.body() instanceof MultiValuedKeyValueQueryResponse);
            MultiValuedKeyValueQueryResponse response = (MultiValuedKeyValueQueryResponse) reply.body();
            context.assertEquals(1, response.getResults().size());
            context.assertTrue(response.getResults().containsKey("a2V5"));//"key" as UT8/b64
            context.assertEquals("dmFsdWU=", response.getResults().get("a2V5"));//"value" as UT8/b64

            context.assertTrue(iterator.closed);

        }));


    }));


}
 
Example #30
Source File: ScalarKeyValueQueryVerticleTest.java    From kiqr with Apache License 2.0 3 votes vote down vote up
@Test
public void notFound(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("key")).thenReturn(null);


    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 exception = (ReplyException) handler;
            context.assertEquals(404, exception.failureCode());

        }));


    }));


}