Skip to content

Add StreamAlternate structure to StreamInfo response #1306

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

Merged
merged 1 commit into from
Apr 21, 2025
Merged
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
Add StreamAlternate structure to StreamInfo response
  • Loading branch information
scottf committed Apr 21, 2025
commit a7d87dc1de862219d46470d9ddc01a95584c8c70
50 changes: 50 additions & 0 deletions src/main/java/io/nats/client/api/StreamAlternate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2025 The NATS Authors
// Licensed 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 io.nats.client.api;

import io.nats.client.support.JsonValue;
import io.nats.client.support.JsonValueUtils;

import java.util.List;

import static io.nats.client.support.ApiConstants.*;
import static io.nats.client.support.JsonValueUtils.readString;

public class StreamAlternate {
private final String name;
private final String domain;
private final String cluster;

static List<StreamAlternate> optionalListOf(JsonValue vSourceInfos) {
return JsonValueUtils.optionalListOf(vSourceInfos, StreamAlternate::new);
}

StreamAlternate(JsonValue vLost) {
name = readString(vLost, NAME);
domain = readString(vLost, DOMAIN);
cluster = readString(vLost, CLUSTER);
}

public String getName() {
return name;
}

public String getDomain() {
return domain;
}

public String getCluster() {
return cluster;
}
}
6 changes: 6 additions & 0 deletions src/main/java/io/nats/client/api/StreamInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class StreamInfo extends ApiResponse<StreamInfo> {
private final ClusterInfo clusterInfo;
private final MirrorInfo mirrorInfo;
private final List<SourceInfo> sourceInfos;
private final List<StreamAlternate> alternates;
private final ZonedDateTime timestamp;

public StreamInfo(Message msg) {
Expand All @@ -49,6 +50,7 @@ public StreamInfo(JsonValue vStreamInfo) {
clusterInfo = ClusterInfo.optionalInstance(readValue(jv, CLUSTER));
mirrorInfo = MirrorInfo.optionalInstance(readValue(jv, MIRROR));
sourceInfos = SourceInfo.optionalListOf(readValue(jv, SOURCES));
alternates = StreamAlternate.optionalListOf(readValue(jv, ALTERNATES));
timestamp = readDate(jv, TIMESTAMP);
}

Expand Down Expand Up @@ -92,6 +94,10 @@ public StreamConfiguration getConfig() {
return config;
}

public List<StreamAlternate> getAlternates() {
return alternates;
}

/**
* Gets the server time the info was gathered
* @return the server gathered timed
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/io/nats/client/support/ApiConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public interface ApiConstants {
String ALLOW_DIRECT = "allow_direct";
String ALLOW_MSG_TTL = "allow_msg_ttl";
String ALLOW_ROLLUP_HDRS = "allow_rollup_hdrs";
String AVERAGE_PROCESSING_TIME = "average_processing_time";
String MIRROR_DIRECT = "mirror_direct";
String ALTERNATES = "alternates";
String API = "api";
String API_URL = "api_url";
String AUTH_REQUIRED = "auth_required";
String AVERAGE_PROCESSING_TIME = "average_processing_time";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Properly sorted

String BACKOFF = "backoff";
String BATCH = "batch";
String BUCKET = "bucket";
Expand Down Expand Up @@ -131,6 +131,7 @@ public interface ApiConstants {
String METADATA = "metadata";
String MTIME = "mtime";
String MIRROR = "mirror";
String MIRROR_DIRECT = "mirror_direct";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Properly sorted

String MSGS = "msgs";
String MULTI_LAST = "multi_last";
String NAME = "name";
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/io/nats/client/api/StreamInfoTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ private void validateStreamInfo(StreamInfo si) {
validateSourceInfo(si.getSourceInfos().get(0), 17);
validateSourceInfo(si.getSourceInfos().get(1), 18);

assertEquals(2, si.getAlternates().size());
validateStreamAlternate(si.getAlternates().get(0), 19);
validateStreamAlternate(si.getAlternates().get(1), 20);

si = new StreamInfo(JsonValue.EMPTY_MAP);
assertNull(si.getCreateTime());
assertNotNull(si.getStreamState());
Expand All @@ -180,6 +184,13 @@ private static void validateSourceInfo(SourceInfo sourceInfo, int id) {
StreamConfigurationTests.validateSubjectTransforms(sourceInfo.getSubjectTransforms(), 2, "" + id);
}

private static void validateStreamAlternate(StreamAlternate streamAlternate, int id) {
assertNotNull(streamAlternate.toString()); // coverage
assertEquals("alt" + id, streamAlternate.getName());
assertEquals("domain" + id, streamAlternate.getDomain());
assertEquals("cluster" + id, streamAlternate.getCluster());
}

private static void validateExternal(External e, int id) {
assertNotNull(e);
assertNotNull(e.toString()); // coverage
Expand Down
12 changes: 12 additions & 0 deletions src/test/resources/data/StreamInfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,17 @@
{"src":"18_st_src1","dest":"18_st_dest1"}
]
}
],
"alternates": [
{
"name": "alt19",
"domain": "domain19",
"cluster": "cluster19"
},
{
"name": "alt20",
"domain": "domain20",
"cluster": "cluster20"
}
]
}
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy