Skip to content

Commit

Permalink
Remove some usage of Google ImmutableMap [HZ-4214] (#511)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: e936d66ddea07a64410fd34d03d1d9344c6d4c97
  • Loading branch information
orcunc authored and actions-user committed Jan 25, 2024
1 parent bbb7a82 commit 2abb4cd
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ public void test_resolveFields() {
List<MappingField> fields = CsvResolver.resolveFields(headers);

// then
assertThat(fields).hasSize(2);
assertThat(fields.get(0)).isEqualTo(new MappingField("field1", QueryDataType.VARCHAR));
assertThat(fields.get(1)).isEqualTo(new MappingField("field2", QueryDataType.VARCHAR));
assertThat(fields)
.hasSize(2)
.contains(new MappingField("field1", QueryDataType.VARCHAR))
.contains(new MappingField("field2", QueryDataType.VARCHAR));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.hazelcast.jet.sql.impl.connector.map;

import com.google.common.collect.ImmutableMap;
import com.hazelcast.jet.sql.SqlTestSupport;
import com.hazelcast.jet.sql.impl.connector.map.model.AllTypesValue;
import com.hazelcast.jet.sql.impl.connector.map.model.InsuredPerson;
Expand Down Expand Up @@ -346,7 +345,7 @@ public void test_allTypes() {
OffsetDateTime.ofInstant(ofEpochMilli(1586953414200L), systemDefault()),
OffsetDateTime.of(2020, 4, 15, 12, 23, 34, 200_000_000, UTC),
OffsetDateTime.of(2020, 4, 15, 12, 23, 34, 200_000_000, UTC),
ImmutableMap.of(42, 43),
Map.of(42, 43),
null
)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.hazelcast.sql.impl.schema;

import com.google.common.collect.ImmutableMap;
import com.hazelcast.internal.serialization.InternalSerializationService;
import com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder;
import com.hazelcast.sql.impl.type.QueryDataType;
Expand All @@ -29,6 +28,7 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -49,7 +49,7 @@ public void test_serialization() {
"mapping-type",
null,
new ArrayList<>(singletonList(new MappingField("field-name", QueryDataType.INT, null, null))),
new HashMap<>(ImmutableMap.of("option.key", "option.value"))
new HashMap<>(Map.of("option.key", "option.value"))
);

// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.hazelcast.aws;

import com.google.common.collect.ImmutableMap;
import com.hazelcast.config.InvalidConfigurationException;
import com.hazelcast.spi.discovery.DiscoveryNode;
import com.hazelcast.spi.partitiongroup.PartitionGroupMetaData;
Expand Down Expand Up @@ -187,7 +186,7 @@ public void discoverNodes() {
// given
String privateIp = "192.168.1.15";
String publicIp = "38.146.24.2";
given(awsClient.getAddresses()).willReturn(ImmutableMap.of(privateIp, publicIp));
given(awsClient.getAddresses()).willReturn(Map.of(privateIp, publicIp));

// when
Iterable<DiscoveryNode> nodes = awsDiscoveryStrategy.discoverNodes();
Expand All @@ -214,7 +213,7 @@ public void discoverNodesMultipleAddressesManyPorts() {
awsDiscoveryStrategy = new AwsDiscoveryStrategy(properties, awsClient);

// 2 instances found
given(awsClient.getAddresses()).willReturn(ImmutableMap.of(
given(awsClient.getAddresses()).willReturn(Map.of(
"192.168.1.15", "38.146.24.2",
"192.168.1.16", "38.146.28.15"
));
Expand Down
9 changes: 4 additions & 5 deletions hazelcast/src/test/java/com/hazelcast/aws/AwsEcsApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.hazelcast.aws;

import com.github.tomakehurst.wiremock.junit.WireMockRule;
import com.google.common.collect.ImmutableMap;
import com.hazelcast.aws.AwsEcsApi.Task;
import com.hazelcast.internal.json.JsonArray;
import com.hazelcast.internal.json.JsonObject;
Expand Down Expand Up @@ -86,7 +85,7 @@ public void listTasks() {
// given
String cluster = "arn:aws:ecs:eu-central-1:665466731577:cluster/rafal-test-cluster";
stubListTasks(cluster, null);
Map<String, String> tasksArnToIp = ImmutableMap.of(
Map<String, String> tasksArnToIp = Map.of(
"arn:aws:ecs:us-east-1:012345678910:task/0b69d5c0-d655-4695-98cd-5d2d526d9d5a", "10.0.1.16",
"arn:aws:ecs:us-east-1:012345678910:task/51a01bdf-d00e-487e-ab14-7645330b6207", "10.0.1.219");
stubDescribeTasks(tasksArnToIp, cluster);
Expand All @@ -108,7 +107,7 @@ public void listTasksFiltered() {
AwsEcsApi awsEcsApi = new AwsEcsApi(endpoint, awsConfig, requestSigner, CLOCK);

stubListTasks("arn:aws:ecs:eu-central-1:665466731577:cluster/rafal-test-cluster", "family-name");
stubDescribeTasks(ImmutableMap.of(
stubDescribeTasks(Map.of(
"arn:aws:ecs:us-east-1:012345678910:task/0b69d5c0-d655-4695-98cd-5d2d526d9d5a", "10.0.1.16",
"arn:aws:ecs:us-east-1:012345678910:task/51a01bdf-d00e-487e-ab14-7645330b6207", "10.0.1.219"),
cluster);
Expand All @@ -131,7 +130,7 @@ public void listTasksFilteredByTags() {
AwsEcsApi awsEcsApi = new AwsEcsApi(endpoint, awsConfig, requestSigner, CLOCK);

stubListTasks("arn:aws:ecs:eu-central-1:665466731577:cluster/rafal-test-cluster", null);
stubDescribeTasks(ImmutableMap.of(
stubDescribeTasks(Map.of(
"arn:aws:ecs:us-east-1:012345678910:task/0b69d5c0-d655-4695-98cd-5d2d526d9d5a", "10.0.1.16",
"arn:aws:ecs:us-east-1:012345678910:task/51a01bdf-d00e-487e-ab14-7645330b6207", "10.0.1.219"),
cluster);
Expand All @@ -148,7 +147,7 @@ public void listTasksFilteredByTags() {
public void describeTasks() {
// given
String cluster = "arn:aws:ecs:eu-central-1:665466731577:cluster/rafal-test-cluster";
Map<String, String> tasks = ImmutableMap.of(
Map<String, String> tasks = Map.of(
"arn:aws:ecs:eu-central-1-east-1:012345678910:task/0b69d5c0-d655-4695-98cd-5d2d526d9d5a", "10.0.1.16",
"arn:aws:ecs:eu-central-1:012345678910:task/51a01bdf-d00e-487e-ab14-7645330b6207", "10.0.1.219");
stubDescribeTasks(tasks, cluster);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.hazelcast.internal.usercodedeployment.impl.filter;

import com.google.common.collect.ImmutableMap;
import com.hazelcast.cluster.Member;
import com.hazelcast.internal.util.filter.AlwaysApplyFilter;
import com.hazelcast.internal.util.filter.Filter;
Expand Down Expand Up @@ -64,7 +63,7 @@ public void whenStringHasUnknownPrefix_thenThrowIllegalArgumentException() {
@Test
public void givenMemberAttributeFilterIsUsed_whenMemberAttributeIsPresent_thenFilterMatches() {
Filter<Member> memberFilter = MemberProviderFilterParser.parseMemberFilter("HAS_ATTRIBUTE:foo");
Map<String, String> attributes = ImmutableMap.of(
Map<String, String> attributes = Map.of(
"foo", "bar"
);
Member mockMember = createMockMemberWithAttributes(attributes);
Expand All @@ -74,7 +73,7 @@ public void givenMemberAttributeFilterIsUsed_whenMemberAttributeIsPresent_thenFi
@Test
public void givenMemberAttributeFilterIsUsed_whenMemberAttributeIsNotPresent_thenFilterDoesNotMatch() {
Filter<Member> memberFilter = MemberProviderFilterParser.parseMemberFilter("HAS_ATTRIBUTE:foo");
Map<String, String> attributes = ImmutableMap.of(
Map<String, String> attributes = Map.of(
"bar", "other"
);
Member mockMember = createMockMemberWithAttributes(attributes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.hazelcast.jet.core;

import com.google.common.collect.ImmutableMap;
import com.hazelcast.cache.ICache;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.collection.IList;
Expand Down Expand Up @@ -90,7 +89,7 @@ public void when_serializerIsNotRegistered_then_mapThrowsException() {
@Test
public void when_serializerIsRegistered_then_itIsAvailableForLocalMapSource() {
Map<Integer, Value> map = client().getMap(SOURCE_MAP_NAME);
map.putAll(ImmutableMap.of(1, new Value(1), 2, new Value(2)));
map.putAll(Map.of(1, new Value(1), 2, new Value(2)));

Pipeline pipeline = Pipeline.create();
pipeline.readFrom(Sources.<Integer, Value>map(SOURCE_MAP_NAME))
Expand All @@ -111,7 +110,7 @@ public void when_serializerIsRegistered_then_itIsAvailableForLocalMapSink() {

Map<Integer, Value> map = client().getMap(SINK_MAP_NAME);
assertThat(map).containsExactlyInAnyOrderEntriesOf(
ImmutableMap.of(1, new Value(1), 2, new Value(2))
Map.of(1, new Value(1), 2, new Value(2))
);
}

Expand All @@ -125,7 +124,7 @@ public void when_serializerIsNotRegistered_then_cacheThrowsException() {
@Test
public void when_serializerIsRegistered_then_itIsAvailableForLocalCacheSource() {
Cache<Integer, Value> map = client().getCacheManager().getCache(SOURCE_CACHE_NAME);
map.putAll(ImmutableMap.of(1, new Value(1), 2, new Value(2)));
map.putAll(Map.of(1, new Value(1), 2, new Value(2)));

Pipeline pipeline = Pipeline.create();
pipeline.readFrom(Sources.<Integer, Value>cache(SOURCE_CACHE_NAME))
Expand All @@ -147,7 +146,7 @@ public void when_serializerIsRegistered_then_itIsAvailableForLocalCacheSink() {
ICache<Integer, Value> cache = client().getCacheManager().getCache(SINK_CACHE_NAME);
assertThat(cache).hasSize(2);
assertThat(cache.getAll(Set.of(1, 2))).containsExactlyInAnyOrderEntriesOf(
ImmutableMap.of(1, new Value(1), 2, new Value(2))
Map.of(1, new Value(1), 2, new Value(2))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@

package com.hazelcast.jet.core.test;

import com.google.common.collect.ImmutableMap;
import com.hazelcast.cluster.Address;
import com.hazelcast.cluster.Cluster;
import com.hazelcast.cluster.Member;
import com.hazelcast.core.HazelcastInstance;
import org.junit.Test;

import java.util.Map;

import static org.junit.Assert.assertArrayEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand All @@ -34,7 +35,7 @@ public void test() throws Exception {
Address a0 = new Address("1.2.3.4", 0);

TestProcessorContext c = new TestProcessorContext()
.setPartitionAssignment(ImmutableMap.of(a0, new int[]{0, 3, 6}));
.setPartitionAssignment(Map.of(a0, new int[]{0, 3, 6}));

HazelcastInstance mockHazelcastInstance = mock(HazelcastInstance.class);
Cluster mockCluster = mock(Cluster.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.hazelcast.jet.impl.execution.init;

import com.google.common.collect.ImmutableMap;
import com.hazelcast.cluster.Address;
import com.hazelcast.test.HazelcastParallelParametersRunnerFactory;
import com.hazelcast.test.HazelcastParametrizedRunner;
Expand All @@ -30,6 +29,8 @@
import org.junit.runners.Parameterized.Parameters;
import org.junit.runners.Parameterized.UseParametersRunnerFactory;

import java.util.Map;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

Expand Down Expand Up @@ -58,7 +59,7 @@ public void before() throws Exception {
a2 = new Address("1.2.3.4", 2);

a = new PartitionArrangement(
ImmutableMap.of(
Map.of(
a0, new int[]{0, 3, 6},
a1, new int[]{2, 4},
a2, new int[]{1, 5}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.hazelcast.jet.impl.serialization;

import com.google.common.collect.ImmutableMap;
import com.hazelcast.config.SerializationConfig;
import com.hazelcast.config.SerializerConfig;
import com.hazelcast.internal.serialization.impl.AbstractSerializationService;
Expand Down Expand Up @@ -53,8 +52,8 @@ public class DelegatingSerializationServiceTest {
@Test
public void when_triesToRegisterSerializerWithNegativeTypeId_then_Fails() {
// Given
Map<Class<?>, Serializer> serializers = ImmutableMap.of(
Object.class, new StreamSerializer<Object>() {
Map<Class<?>, Serializer> serializers = Map.of(
Object.class, new StreamSerializer<>() {
@Override
public int getTypeId() {
return -1;
Expand All @@ -80,7 +79,7 @@ public Value read(ObjectDataInput objectDataInput) {
@Test
public void when_triesToRegisterTwoSerializersWithSameTypeId_then_Fails() {
// Given
Map<Class<?>, Serializer> serializers = ImmutableMap.of(
Map<Class<?>, Serializer> serializers = Map.of(
int.class, new ValueSerializer(),
long.class, new ValueSerializer()
);
Expand Down Expand Up @@ -122,14 +121,14 @@ public void when_doesNotFind_then_Delegates() {
public void when_multipleTypeSerializersRegistered_then_localHasPrecedence() {
// Given
Serializer serializer = new ValueSerializer();
Map<Class<?>, Serializer> serializers = ImmutableMap.of(Byte.class, serializer);
Map<Class<?>, Serializer> serializers = Map.of(Byte.class, serializer);

DelegatingSerializationService service = new DelegatingSerializationService(serializers, DELEGATE);

// When
// Then
assertThat(service.serializerFor(TYPE_ID).getImpl()).isEqualTo(serializer);
assertThat(service.serializerFor(Byte.valueOf((byte) 1), false).getImpl()).isEqualTo(serializer);
assertThat(service.serializerFor((byte) 1, false).getImpl()).isEqualTo(serializer);
}

@Test
Expand Down

0 comments on commit 2abb4cd

Please sign in to comment.