You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2022/09/22 13:46:16 UTC
[GitHub] [kafka] clolov commented on a diff in pull request #12527: KAFKA-14133: Replace EasyMock with Mockito in streams tests
clolov commented on code in PR #12527:
URL: https://github.com/apache/kafka/pull/12527#discussion_r977677573
##########
streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingTimestampedWindowBytesStoreTest.java:
##########
@@ -63,129 +55,79 @@ public class ChangeLoggingTimestampedWindowBytesStoreTest {
@Before
public void setUp() {
store = new ChangeLoggingTimestampedWindowBytesStore(inner, false);
+ store.init((StateStoreContext) context, store);
}
- private void init() {
- EasyMock.expect(context.taskId()).andReturn(taskId).anyTimes();
- EasyMock.expect(context.recordCollector()).andReturn(collector).anyTimes();
- EasyMock.expect(context.recordMetadata()).andReturn(Optional.empty()).anyTimes();
- inner.init((StateStoreContext) context, store);
- EasyMock.expectLastCall();
- EasyMock.replay(inner, context);
-
- store.init((StateStoreContext) context, store);
+ @After
+ public void tearDown() {
+ verify(inner).init((StateStoreContext) context, store);
}
@SuppressWarnings("deprecation")
@Test
public void shouldDelegateDeprecatedInit() {
- inner.init((ProcessorContext) context, store);
- EasyMock.expectLastCall();
- EasyMock.replay(inner);
store.init((ProcessorContext) context, store);
- EasyMock.verify(inner);
+
+ verify(inner).init((ProcessorContext) context, store);
}
@Test
public void shouldDelegateInit() {
- inner.init((StateStoreContext) context, store);
- EasyMock.expectLastCall();
- EasyMock.replay(inner);
- store.init((StateStoreContext) context, store);
- EasyMock.verify(inner);
+ // testing the combination of setUp and tearDown
}
@Test
@SuppressWarnings("deprecation")
public void shouldLogPuts() {
- EasyMock.expect(inner.getPosition()).andReturn(Position.emptyPosition()).anyTimes();
- inner.put(bytesKey, valueAndTimestamp, 0);
- EasyMock.expectLastCall();
-
- init();
-
final Bytes key = WindowKeySchema.toStoreKeyBinary(bytesKey, 0, 0);
+ when(inner.getPosition()).thenReturn(Position.emptyPosition());
- EasyMock.reset(context);
- EasyMock.expect(context.recordMetadata()).andStubReturn(Optional.empty());
- context.logChange(store.name(), key, value, 42, Position.emptyPosition());
-
- EasyMock.replay(context);
store.put(bytesKey, valueAndTimestamp, context.timestamp());
- EasyMock.verify(inner, context);
+ verify(inner).put(bytesKey, valueAndTimestamp, 0);
+ verify(context).logChange(store.name(), key, value, 42, Position.emptyPosition());
}
@Test
public void shouldLogPutsWithPosition() {
- EasyMock.expect(inner.getPosition()).andReturn(POSITION).anyTimes();
- inner.put(bytesKey, valueAndTimestamp, 0);
- EasyMock.expectLastCall();
-
- init();
-
final Bytes key = WindowKeySchema.toStoreKeyBinary(bytesKey, 0, 0);
+ when(inner.getPosition()).thenReturn(POSITION);
- EasyMock.reset(context);
- final RecordMetadata recordContext = new ProcessorRecordContext(0L, 1L, 0, "", new RecordHeaders());
- EasyMock.expect(context.recordMetadata()).andStubReturn(Optional.of(recordContext));
- final Position position = Position.fromMap(mkMap(mkEntry("", mkMap(mkEntry(0, 1L)))));
- context.logChange(store.name(), key, value, 42, position);
-
- EasyMock.replay(context);
store.put(bytesKey, valueAndTimestamp, context.timestamp());
- EasyMock.verify(inner, context);
+ verify(inner).put(bytesKey, valueAndTimestamp, 0);
+ verify(context).logChange(store.name(), key, value, 42, POSITION);
}
@Test
public void shouldDelegateToUnderlyingStoreWhenFetching() {
- EasyMock
- .expect(inner.fetch(bytesKey, 0, 10))
- .andReturn(KeyValueIterators.emptyWindowStoreIterator());
-
- init();
-
store.fetch(bytesKey, ofEpochMilli(0), ofEpochMilli(10));
- EasyMock.verify(inner);
+
+ verify(inner).fetch(bytesKey, 0, 10);
}
@Test
public void shouldDelegateToUnderlyingStoreWhenFetchingRange() {
- EasyMock
- .expect(inner.fetch(bytesKey, bytesKey, 0, 1))
- .andReturn(KeyValueIterators.emptyIterator());
-
- init();
-
store.fetch(bytesKey, bytesKey, ofEpochMilli(0), ofEpochMilli(1));
- EasyMock.verify(inner);
+
+ verify(inner).fetch(bytesKey, bytesKey, 0, 1);
}
@Test
@SuppressWarnings("deprecation")
public void shouldRetainDuplicatesWhenSet() {
store = new ChangeLoggingTimestampedWindowBytesStore(inner, true);
- EasyMock.expect(inner.getPosition()).andReturn(Position.emptyPosition()).anyTimes();
- inner.put(bytesKey, valueAndTimestamp, 0);
- EasyMock.expectLastCall().times(2);
-
- init();
-
+ store.init((StateStoreContext) context, store);
Review Comment:
The `@Before` sets the boolean parameter for retaining duplicates to false. As far as I understand this test wants to tests that duplicates are retained.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org