-
Notifications
You must be signed in to change notification settings - Fork 0
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
Snapshots test #18
Snapshots test #18
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was much easier to understand. I left a few suggestions that you can take or leave. Not critical.
@@ -0,0 +1,251 @@ | |||
export class PulsarClientMock { | |||
// A map used to simulate an in-memory store for messages. The keys are topic names, and the values are arrays of message objects. | |||
static inMemoryStore = new Map(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with all these being static, it will not be possible to run more than one test client on a given system. I am not sure that is a good idea ... perhaps good enough for now, but prolly worth the small refactor to make then instance fields
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a big, but a feature - I want the data to persist client instance restart, so we can demonstrate how server side acks work
// A map where keys are topic names and values are arrays of receive function invocations (listeners). These listeners are called to notify about new messages. | ||
static listeners = new Map(); | ||
|
||
// The default time in milliseconds to wait before a message is considered not acknowledged (acknowledged messages are removed from visibility to simulate message acknowledgment behavior). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do ack's need timeouts? Is that something pulsar-like that we are trying to simulate? What is the concept of "visibility"?
send: async (message) => { | ||
const messageId = new MessageId(`message-${++PulsarClientMock.messageIdCounter}`); | ||
const messageInstance = new Message(topic, undefined, message.data, messageId, Date.now(), Date.now(), 0, ''); | ||
const messages = PulsarClientMock.inMemoryStore.get(topic) || []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the || []
will result in a phantom topic that is not tracked anywhere
/** | ||
* receives either returns the next visible message, or blocks until a message is available. | ||
*/ | ||
receive: () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we don't have TS to declare return type is promise, marking this method async
may be a good idea for documenting that it returns a Promise
return new Promise((resolve) => { | ||
const tryResolve = () => { | ||
const messages = PulsarClientMock.inMemoryStore.get(topic) || []; | ||
const messageIndex = messages.findIndex(m => !m.subscriberIds.has(subscriberId)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use .find() here instead of findIndex
Description
Type of Change
Checklist