Skip to content

Commit

Permalink
[TEST] added cross version tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aricart committed Jun 8, 2023
1 parent b115d4c commit 43ed5bc
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
7 changes: 4 additions & 3 deletions jetstream/objectstore.ts
Expand Up @@ -845,15 +845,16 @@ export class ObjectStoreImpl implements ObjectStore {
return Promise.reject(err);
}
try {
const si = await this.jsm.streams.info(this.name);
const si = await this.jsm.streams.info(this.stream);
const { subjects } = si.config;

const keys = adapters.find((k) => {
const a = k.streamSubjectNames();
return a.includes(subjects[0]) && a.includes(subjects[1]);
});
if (!keys) {
return Promise.reject("unknown object store configuration");
return Promise.reject(
new Error("unknown objectstore version configuration"),
);
}
this.keys = keys;
} catch (err) {
Expand Down
47 changes: 47 additions & 0 deletions jetstream/tests/objectstore_test.ts
Expand Up @@ -1055,3 +1055,50 @@ Deno.test("objectstore - put/get blob", async () => {

await cleanup(ns, nc);
});

Deno.test("objectstore - v1/v2", async () => {
const { ns, nc } = await setup(jetstreamServerConf({}, true));
if (await notCompatible(ns, nc, "2.6.3")) {
return;
}

const js = nc.jetstream();
const v1 = await js.views.os("v1", { description: "testing", version: 1 });
assertEquals(v1.version(), 1);
await v1.putBlob({ name: "A" }, new Uint8Array(10));

let { subjects } = (await v1.status()).streamInfo.config;
assert(subjects[0].startsWith("$O."));

let v = await js.views.os("v1");
assertEquals(v.version(), 1);
let data = await v.getBlob("A");
assertEquals(data?.length, 10);

const v2 = await js.views.os("v2", { version: 2 });
assertEquals(v2.version(), 2);
await v2.putBlob({ name: "A" }, new Uint8Array(11));

v = await js.views.os("v2", { version: 1 });
assertEquals(v.version(), 2);
data = await v.getBlob("A");
assertEquals(data?.length, 11);

let v3 = await js.views.os("v3", { description: "testing" });
const sc = (await v3.status()).streamInfo.config;
subjects = sc.subjects.map((s) => {
return s.replaceAll("$O2.", "$O3.");
});
const jsm = await js.jetstreamManager();
await jsm.streams.update(sc.name, { subjects });

await assertRejects(
async () => {
await js.views.os("v3");
},
Error,
"unknown objectstore version configuration",
);

await cleanup(ns, nc);
});

0 comments on commit 43ed5bc

Please sign in to comment.