Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MINOR: Rewrite unchecked operations in Mock API #19071

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from
Open
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 @@ -16775,7 +16775,7 @@ fooTopicName, new TopicMetadata(fooTopicId, fooTopicName, 6)))
acls.put(fooTopicName, AuthorizationResult.ALLOWED);
acls.put(barTopicName, AuthorizationResult.DENIED);
when(authorizer.authorize(any(), any())).thenAnswer(invocation -> {
List<Action> actions = invocation.getArgument(1, List.class);
List<Action> actions = invocation.getArgument(1);
return actions.stream()
.map(action -> acls.getOrDefault(action.resourcePattern().name(), AuthorizationResult.DENIED))
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,13 @@
import java.util.Properties;

import static java.util.Arrays.asList;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;

@ExtendWith(MockitoExtension.class)
Expand Down Expand Up @@ -352,12 +353,10 @@ public void testStateStoreLazyEval() {
final String topic1 = "topic1";
final String topic2 = "topic2";

final KTableImpl<String, String, String> table1 =
(KTableImpl<String, String, String>) builder.table(topic1, consumed);
final var table1 = builder.table(topic1, consumed);
builder.table(topic2, consumed);

final KTableImpl<String, String, Integer> table1Mapped =
(KTableImpl<String, String, Integer>) table1.mapValues(s -> Integer.valueOf(s));
final var table1Mapped = table1.mapValues(s -> Integer.valueOf(s));
table1Mapped.filter((key, value) -> (value % 2) == 0);

try (final TopologyTestDriver driver = new TopologyTestDriver(builder.build(), props)) {
Expand All @@ -371,15 +370,11 @@ public void testStateStore() {
final String topic1 = "topic1";
final String topic2 = "topic2";

final KTableImpl<String, String, String> table1 =
(KTableImpl<String, String, String>) builder.table(topic1, consumed);
final KTableImpl<String, String, String> table2 =
(KTableImpl<String, String, String>) builder.table(topic2, consumed);
final var table1 = builder.table(topic1, consumed);
final var table2 = builder.table(topic2, consumed);

final KTableImpl<String, String, Integer> table1Mapped =
(KTableImpl<String, String, Integer>) table1.mapValues(s -> Integer.valueOf(s));
final KTableImpl<String, Integer, Integer> table1MappedFiltered =
(KTableImpl<String, Integer, Integer>) table1Mapped.filter((key, value) -> (value % 2) == 0);
final var table1Mapped = table1.mapValues(s -> Integer.valueOf(s));
final var table1MappedFiltered = table1Mapped.filter((key, value) -> (value % 2) == 0);
table2.join(table1MappedFiltered, (v1, v2) -> v1 + v2);

try (final TopologyTestDriver driver = new TopologyTestDriver(builder.build(), props)) {
Expand All @@ -391,24 +386,20 @@ public void testStateStore() {
public void shouldNotEnableSendingOldValuesIfNotMaterializedAlreadyAndNotForcedToMaterialize() {
final StreamsBuilder builder = new StreamsBuilder();

final KTableImpl<String, String, String> table =
(KTableImpl<String, String, String>) builder.table("topic1", consumed);
final var kTable = assertInstanceOf(KTableImpl.class, builder.table("topic1", consumed));
kTable.enableSendingOldValues(false);

table.enableSendingOldValues(false);

assertThat(table.sendingOldValueEnabled(), is(false));
assertFalse(kTable.sendingOldValueEnabled());
}

@Test
public void shouldEnableSendingOldValuesIfNotMaterializedAlreadyButForcedToMaterialize() {
final StreamsBuilder builder = new StreamsBuilder();

final KTableImpl<String, String, String> table =
(KTableImpl<String, String, String>) builder.table("topic1", consumed);

table.enableSendingOldValues(true);
final var kTable = assertInstanceOf(KTableImpl.class, builder.table("topic1", consumed));
kTable.enableSendingOldValues(true);

assertThat(table.sendingOldValueEnabled(), is(true));
assertTrue(kTable.sendingOldValueEnabled());
}

private void assertTopologyContainsProcessor(final Topology topology, final String processorName) {
Expand All @@ -429,8 +420,7 @@ public void shouldCreateSourceAndSinkNodesForRepartitioningTopic() throws Except
final String topic1 = "topic1";
final String storeName1 = "storeName1";

final KTableImpl<String, String, String> table1 =
(KTableImpl<String, String, String>) builder.table(
final var table1 = builder.table(
topic1,
consumed,
Materialized.<String, String, KeyValueStore<Bytes, byte[]>>as(storeName1)
Expand Down Expand Up @@ -587,19 +577,16 @@ public void shouldThrowNullPointerOnTransformValuesWithKeyWhenTransformerSupplie
assertThrows(NullPointerException.class, () -> table.transformValues(null));
}

@SuppressWarnings("unchecked")
@Test
public void shouldThrowNullPointerOnTransformValuesWithKeyWhenMaterializedIsNull() {
final ValueTransformerWithKeySupplier<String, String, ?> valueTransformerSupplier =
mock(ValueTransformerWithKeySupplier.class);
final ValueTransformerWithKeySupplier<String, String, ?> valueTransformerSupplier = mock();
Comment on lines -593 to +582
Copy link
Contributor

@m1a2st m1a2st Mar 2, 2025

Choose a reason for hiding this comment

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

I use ./gradlew clean build -x test command on this branch, It still have the warning message
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for checking again.
I’ve fixed it.

assertThrows(NullPointerException.class, () -> table.transformValues(valueTransformerSupplier, (Materialized<String, Object, KeyValueStore<Bytes, byte[]>>) null));
}

@SuppressWarnings("unchecked")

@Test
public void shouldThrowNullPointerOnTransformValuesWithKeyWhenStoreNamesNull() {
final ValueTransformerWithKeySupplier<String, String, ?> valueTransformerSupplier =
mock(ValueTransformerWithKeySupplier.class);
final ValueTransformerWithKeySupplier<String, String, ?> valueTransformerSupplier = mock();
assertThrows(NullPointerException.class, () -> table.transformValues(valueTransformerSupplier, (String[]) null));
}
}