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

[FEAT] updated StreamInfo to report alternates #291

Merged
merged 2 commits into from
May 11, 2022
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
6 changes: 6 additions & 0 deletions nats-base-client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,13 +546,19 @@ export interface ApiPagedRequest {
offset: number;
}

export interface StreamAlternate {
name: string;
cluster: string;
}

export interface StreamInfo {
config: StreamConfig;
created: number; // in ns
state: StreamState;
cluster?: ClusterInfo;
mirror?: StreamSourceInfo;
sources?: StreamSourceInfo[];
alternates?: StreamAlternate[];
}

export interface StreamConfig extends StreamUpdateConfig {
Expand Down
31 changes: 31 additions & 0 deletions tests/jetstream_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { NatsServer } from "./helpers/launcher.ts";

import {
cleanup,
Expand Down Expand Up @@ -3103,3 +3104,33 @@ Deno.test("jetstream - pull error: js not enabled", async () => {
await expectError(ErrorCode.JetStreamNotEnabled, 0);
await cleanup(ns, nc);
});

Deno.test("jetstream - mirror alternates", async () => {
const servers = await NatsServer.jetstreamCluster(3);
const nc = await connect({ port: servers[0].port });
if (await notCompatible(servers[0], nc, "2.8.2")) {
await NatsServer.stopAll([servers[1], servers[2]]);
return;
}

const jsm = await nc.jetstreamManager();
await jsm.streams.add({ name: "src", subjects: ["A", "B"] });

const nc1 = await connect({ port: servers[1].port });
const jsm1 = await nc1.jetstreamManager();

await jsm1.streams.add({
name: "mirror",
mirror: {
name: "src",
},
});

const n = await jsm1.streams.find("A");
const si = await jsm1.streams.info(n);
assertEquals(si.alternates?.length, 2);
Copy link
Member

Choose a reason for hiding this comment

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

Probably need to assert the server version at top of test? I think this is available only since a recent release of the server.

Copy link
Member Author

Choose a reason for hiding this comment

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

FIXED


await nc.close();
await nc1.close();
await NatsServer.stopAll(servers);
});