mjsax commented on code in PR #13264:
URL: https://github.com/apache/kafka/pull/13264#discussion_r1117769530


##########
streams/src/test/java/org/apache/kafka/streams/state/internals/KeyValueStoreWrapperTest.java:
##########
@@ -0,0 +1,356 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.streams.state.internals;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.apache.kafka.streams.errors.InvalidStateStoreException;
+import org.apache.kafka.streams.processor.StateStoreContext;
+import org.apache.kafka.streams.processor.api.ProcessorContext;
+import org.apache.kafka.streams.query.Position;
+import org.apache.kafka.streams.query.PositionBound;
+import org.apache.kafka.streams.query.Query;
+import org.apache.kafka.streams.query.QueryConfig;
+import org.apache.kafka.streams.query.QueryResult;
+import org.apache.kafka.streams.state.KeyValueStore;
+import org.apache.kafka.streams.state.TimestampedKeyValueStore;
+import org.apache.kafka.streams.state.ValueAndTimestamp;
+import org.apache.kafka.streams.state.VersionedKeyValueStore;
+import org.apache.kafka.streams.state.VersionedRecord;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
+public class KeyValueStoreWrapperTest {
+
+    private static final String STORE_NAME = "kvStore";
+    private static final String KEY = "k";
+    private static final ValueAndTimestamp<String> VALUE_AND_TIMESTAMP
+        = ValueAndTimestamp.make("v", 8L);
+
+    @Mock
+    private TimestampedKeyValueStore<String, String> timestampedStore;
+    @Mock
+    private VersionedKeyValueStore<String, String> versionedStore;
+    @Mock
+    private ProcessorContext context;
+    @Mock
+    private Query query;
+    @Mock
+    private PositionBound positionBound;
+    @Mock
+    private QueryConfig queryConfig;
+    @Mock
+    private QueryResult result;
+    @Mock
+    private Position position;
+
+    private KeyValueStoreWrapper<String, String> wrapper;
+
+    @Test
+    public void shouldThrowOnNonTimestampedOrVersionedStore() {
+        
when(context.getStateStore(STORE_NAME)).thenReturn(mock(KeyValueStore.class));
+
+        assertThrows(InvalidStateStoreException.class, () -> new 
KeyValueStoreWrapper<>(context, STORE_NAME));
+    }
+
+    @Test
+    public void shouldGetFromTimestampedStore() {
+        givenWrapperWithTimestampedStore();
+        when(timestampedStore.get(KEY)).thenReturn(VALUE_AND_TIMESTAMP);
+
+        assertThat(wrapper.get(KEY), equalTo(VALUE_AND_TIMESTAMP));
+    }
+
+    @Test
+    public void shouldGetFromVersionedStore() {
+        givenWrapperWithVersionedStore();
+        when(versionedStore.get(KEY)).thenReturn(
+            new VersionedRecord<>(
+                VALUE_AND_TIMESTAMP.value(),
+                VALUE_AND_TIMESTAMP.timestamp())
+        );
+
+        assertThat(wrapper.get(KEY), equalTo(VALUE_AND_TIMESTAMP));
+    }
+
+    @Test
+    public void shouldGetNullFromTimestampedStore() {
+        givenWrapperWithTimestampedStore();
+        when(timestampedStore.get(KEY)).thenReturn(null);
+
+        assertThat(wrapper.get(KEY), nullValue());
+    }
+
+    @Test
+    public void shouldGetNullFromVersionedStore() {
+        givenWrapperWithVersionedStore();
+        when(versionedStore.get(KEY)).thenReturn(null);
+
+        assertThat(wrapper.get(KEY), nullValue());
+    }
+
+    @Test
+    public void shouldPutToTimestampedStore() {
+        givenWrapperWithTimestampedStore();
+
+        wrapper.put(KEY, VALUE_AND_TIMESTAMP.value(), 
VALUE_AND_TIMESTAMP.timestamp());
+
+        verify(timestampedStore).put(KEY, VALUE_AND_TIMESTAMP);
+    }
+
+    @Test
+    public void shouldPutToVersionedStore() {
+        givenWrapperWithVersionedStore();
+
+        wrapper.put(KEY, VALUE_AND_TIMESTAMP.value(), 
VALUE_AND_TIMESTAMP.timestamp());
+
+        verify(versionedStore).put(KEY, VALUE_AND_TIMESTAMP.value(), 
VALUE_AND_TIMESTAMP.timestamp());
+    }
+
+    @Test
+    public void shouldPutNullToTimestampedStore() {
+        givenWrapperWithTimestampedStore();
+
+        wrapper.put(KEY, null, VALUE_AND_TIMESTAMP.timestamp());
+
+        verify(timestampedStore).put(KEY, null);
+    }
+
+    @Test
+    public void shouldPutNullToVersionedStore() {
+        givenWrapperWithVersionedStore();
+
+        wrapper.put(KEY, null, VALUE_AND_TIMESTAMP.timestamp());
+
+        verify(versionedStore).put(KEY, null, VALUE_AND_TIMESTAMP.timestamp());
+    }
+
+    @Test
+    public void shouldGetTimestampedStore() {

Review Comment:
   If we add the `Store store` member, it seem we can cut 50% of the tests 
below?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to