Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ public <T> List<T> stores(final StoreQueryParameters storeQueryParams) {
final Map<TaskId, ? extends Task> tasks = storeQueryParams.staleStoresEnabled() ? streamThread.allTasks() : streamThread.activeTaskMap();
final List<T> stores = new ArrayList<>();
if (keyTaskId != null) {
final T store = validateAndListStores(tasks.get(keyTaskId).getStore(storeName), queryableStoreType, storeName, keyTaskId);
final Task task = tasks.get(keyTaskId);
if (task == null) {
throw new InvalidStateStoreException(
String.format("The specified partition %d for store %s does not exist.",
storeQueryParams.partition(),
storeName));
}
final T store = validateAndListStores(task.getStore(storeName), queryableStoreType, storeName, keyTaskId);
if (store != null) {
return Collections.singletonList(store);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;

public class StreamThreadStateStoreProviderTest {

Expand Down Expand Up @@ -290,6 +292,48 @@ public void shouldReturnEmptyListIfNoStoresFoundWithName() {
provider.stores(StoreQueryParameters.fromNameAndType("not-a-store", QueryableStoreTypes.keyValueStore())));
}

@Test
public void shouldReturnSingleStoreForPartition() {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first two tests are just new test that we missed to add in the original PR.

mockThread(true);
{
final List<ReadOnlyKeyValueStore<String, String>> kvStores =
provider.stores(
StoreQueryParameters
.fromNameAndType("kv-store", QueryableStoreTypes.keyValueStore())
.withPartition(0));
assertEquals(1, kvStores.size());
for (final ReadOnlyKeyValueStore<String, String> store : kvStores) {
assertThat(store, instanceOf(ReadOnlyKeyValueStore.class));
assertThat(store, not(instanceOf(TimestampedKeyValueStore.class)));
}
}
{
final List<ReadOnlyKeyValueStore<String, String>> kvStores =
provider.stores(
StoreQueryParameters
.fromNameAndType("kv-store", QueryableStoreTypes.keyValueStore())
.withPartition(1));
assertEquals(1, kvStores.size());
for (final ReadOnlyKeyValueStore<String, String> store : kvStores) {
assertThat(store, instanceOf(ReadOnlyKeyValueStore.class));
assertThat(store, not(instanceOf(TimestampedKeyValueStore.class)));
}
}
}

@Test
public void shouldThrowForInvalidPartitions() {
mockThread(true);
final InvalidStateStoreException thrown = assertThrows(
InvalidStateStoreException.class,
() -> provider.stores(
StoreQueryParameters
.fromNameAndType("kv-store", QueryableStoreTypes.keyValueStore())
.withPartition(2))
);
assertThat(thrown.getMessage(), equalTo("The specified partition 2 for store kv-store does not exist."));
}

@Test
public void shouldReturnEmptyListIfStoreExistsButIsNotOfTypeValueStore() {
mockThread(true);
Expand Down