Skip to content

Commit

Permalink
Fix test (wrong ordering of map entries)
Browse files Browse the repository at this point in the history
  • Loading branch information
acogoluegnes committed Nov 27, 2024
1 parent 4739a25 commit dd25614
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/rabbitmq/stream/impl/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,9 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)

private static Map<String, String> clientProperties(Map<String, String> fromParameters) {
fromParameters = fromParameters == null ? Collections.emptyMap() : fromParameters;
Map<String, String> clientProperties = new HashMap<>(fromParameters);
Map<String, String> clientProperties = new LinkedHashMap<>(fromParameters);
clientProperties.putAll(ClientProperties.DEFAULT_CLIENT_PROPERTIES);
return Map.copyOf(clientProperties);
return Collections.unmodifiableMap(clientProperties);
}

static void checkMessageFitsInFrame(int maxFrameSize, Codec.EncodedMessage encodedMessage) {
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/com/rabbitmq/stream/impl/ClientProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
package com.rabbitmq.stream.impl;

import java.io.InputStream;
import java.util.Map;
import java.util.Properties;
import java.util.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -37,12 +36,16 @@ public final class ClientProperties {
public static final String VERSION = getVersion();

public static final Map<String, String> DEFAULT_CLIENT_PROPERTIES =
Map.of(
"product", "RabbitMQ Stream",
"version", ClientProperties.VERSION,
"platform", "Java",
"copyright", "Copyright (c) 2020-2024 Broadcom Inc. and/or its subsidiaries.",
"information", "Licensed under the MPL 2.0. See https://www.rabbitmq.com/");
Collections.unmodifiableMap(
new LinkedHashMap<>() {
{
put("product", "RabbitMQ Stream");
put("version", ClientProperties.VERSION);
put("platform", "Java");
put("copyright", "Copyright (c) 2020-2024 Broadcom Inc. and/or its subsidiaries.");
put("information", "Licensed under the MPL 2.0. See https://www.rabbitmq.com/");
}
});

private static String getVersion() {
String version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ private SubscriptionTracker(
properties.putAll(subscriptionProperties);
// we propagate the subscription name, used for monitoring
properties.put("name", this.offsetTrackingReference);
this.subscriptionProperties = Map.copyOf(properties);
this.subscriptionProperties = Collections.unmodifiableMap(properties);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ int doHandle(Client client, ChannelHandlerContext ctx, ByteBuf message) {
if (outstandingRequest == null) {
LOGGER.warn("Could not find outstanding request with correlation ID {}", correlationId);
} else {
outstandingRequest.response().set(Map.copyOf(serverProperties));
outstandingRequest.response().set(Collections.unmodifiableMap(serverProperties));
outstandingRequest.countDown();
}
return read;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

import static java.lang.String.format;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/** {@link SaslConfiguration} that supports our built-in mechanisms. */
public final class DefaultSaslConfiguration implements SaslConfiguration {
Expand All @@ -31,10 +31,14 @@ public final class DefaultSaslConfiguration implements SaslConfiguration {
new DefaultSaslConfiguration(AnonymousSaslMechanism.INSTANCE.getName());

private final Map<String, SaslMechanism> mechanisms =
Map.of(
PlainSaslMechanism.INSTANCE.getName(), PlainSaslMechanism.INSTANCE,
ExternalSaslMechanism.INSTANCE.getName(), ExternalSaslMechanism.INSTANCE,
AnonymousSaslMechanism.INSTANCE.getName(), AnonymousSaslMechanism.INSTANCE);
Collections.unmodifiableMap(
Stream.of(
PlainSaslMechanism.INSTANCE,
ExternalSaslMechanism.INSTANCE,
AnonymousSaslMechanism.INSTANCE)
.collect(
Collectors.toMap(
SaslMechanism::getName, m -> m, (k1, k2) -> k1, LinkedHashMap::new)));

private final String mechanism;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023 Broadcom. All Rights Reserved.
// Copyright (c) 2020-2024 Broadcom. All Rights Reserved.
// The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
//
// This software, the RabbitMQ Stream Java client library, is dual-licensed under the
Expand Down Expand Up @@ -58,6 +58,6 @@ void getSaslMechanismShouldThrowExceptionIfNoMechanismSpecifiedAndNoMatch() {
assertThatThrownBy(() -> configuration.getSaslMechanism(asList("FOO", "BAR")))
.isInstanceOf(IllegalStateException.class)
.hasMessage(
"Unable to agree on a SASL mechanism. Client: PLAIN, ANONYMOUS, EXTERNAL / server FOO, BAR.");
"Unable to agree on a SASL mechanism. Client: PLAIN, EXTERNAL, ANONYMOUS / server FOO, BAR.");
}
}

0 comments on commit dd25614

Please sign in to comment.