-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #654 from nats-io/batch-direct
[FEAT] direct batch
- Loading branch information
Showing
5 changed files
with
161 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ import { | |
fail, | ||
} from "https://deno.land/[email protected]/assert/mod.ts"; | ||
|
||
import { NatsConnectionImpl } from "../../nats-base-client/internal_mod.ts"; | ||
import { NatsConnectionImpl } from "../../nats-base-client/nats.ts"; | ||
import { | ||
deferred, | ||
Empty, | ||
|
@@ -2785,3 +2785,72 @@ Deno.test("jsm - pause/unpause", async () => { | |
|
||
await cleanup(ns, nc); | ||
}); | ||
|
||
Deno.test("jsm - batch direct get multi_last", async () => { | ||
const { ns, nc } = await setup(jetstreamServerConf()); | ||
if (await notCompatible(ns, nc, "2.11.0")) { | ||
return; | ||
} | ||
const jsm = await nc.jetstreamManager() as JetStreamManagerImpl; | ||
await jsm.streams.add({ | ||
name: "A", | ||
subjects: ["a.>"], | ||
storage: StorageType.Memory, | ||
allow_direct: true, | ||
}); | ||
|
||
const js = nc.jetstream(); | ||
await Promise.all([ | ||
js.publish("a.foo", "foo"), | ||
js.publish("a.bar", "bar"), | ||
js.publish("a.baz", "baz"), | ||
]); | ||
|
||
const iter = await jsm.direct.getBatch("A", { | ||
multi_last: ["a.foo", "a.baz"], | ||
}); | ||
|
||
const keys = []; | ||
for await (const m of iter) { | ||
keys.push(m.subject); | ||
} | ||
assertEquals(keys.length, 2); | ||
assertArrayIncludes(keys, ["a.foo", "a.baz"]); | ||
|
||
await cleanup(ns, nc); | ||
}); | ||
|
||
Deno.test("jsm - batch direct get batch", async () => { | ||
const { ns, nc } = await setup(jetstreamServerConf()); | ||
if (await notCompatible(ns, nc, "2.11.0")) { | ||
return; | ||
} | ||
const jsm = await nc.jetstreamManager() as JetStreamManagerImpl; | ||
await jsm.streams.add({ | ||
name: "A", | ||
subjects: ["a.>"], | ||
storage: StorageType.Memory, | ||
allow_direct: true, | ||
}); | ||
|
||
const js = nc.jetstream(); | ||
await Promise.all([ | ||
js.publish("a.foo", "foo"), | ||
js.publish("a.bar", "bar"), | ||
js.publish("a.baz", "baz"), | ||
js.publish("a.foobar", "foobar"), | ||
]); | ||
|
||
const iter = await jsm.direct.getBatch("A", { | ||
batch: 3, | ||
multi_last: [">"], | ||
}); | ||
|
||
const buf = []; | ||
for await (const m of iter) { | ||
buf.push(m); | ||
} | ||
assertEquals(buf.length, 3); | ||
|
||
await cleanup(ns, nc); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters