it("should reset the labeled value", () => { item.changed.mockClear(); item.reset({ a: 5 }, 23456); expect(item.values.get("5")).toEqual({ labels: { a: 5 }, timestamp: 23456, value: 0 }); expect(item.changed).toBeCalledTimes(1); expect(item.changed).toBeCalledWith(0, { a: 5 }, 23456); expect(item.values.size).toBe(2); });
canSendSocketRequestImmediately() { const shouldEnqueue = (this.maxInFlightRequests != null && this.inflight.size >= this.maxInFlightRequests) || this.throttledUntil > Date.now() return !shouldEnqueue }
shouldUseRemoteWorkers() { return ( !this.options.useLocalWorker || this.warmWorkers >= this.workers.size || !this.options.warmWorkers ); }
it('can add subscription information', function() { const subscription = {}; const fields = ['test']; const subscriptionInfo = { subscription: subscription, fields: fields, }; const client = new Client(1, {}); client.addSubscriptionInfo(1, subscriptionInfo); expect(client.subscriptionInfos.size).toBe(1); expect(client.subscriptionInfos.get(1)).toBe(subscriptionInfo); });
/** * @return {number} */ get size() { return this._map.size; }
it('can add requests for one client', function() { const subscription = new Subscription( 'className', { key: 'value' }, 'hash' ); subscription.addClientSubscription(1, 1); subscription.addClientSubscription(1, 2); expect(subscription.clientRequestIds.size).toBe(1); expect(subscription.clientRequestIds.get(1)).toEqual([1, 2]); });
it("should store a value", () => { item.changed.mockClear(); expect(item.values.size).toBe(0); item.set(3); expect(item.values.size).toBe(1); expect(item.values.get("")).toEqual({ labels: {}, timestamp: expect.any(Number), value: 3 }); expect(item.changed).toBeCalledTimes(1); expect(item.changed).toBeCalledWith(3, undefined, undefined); });
it('can be initialized', function() { const subscription = new Subscription( 'className', { key: 'value' }, 'hash' ); expect(subscription.className).toBe('className'); expect(subscription.query).toEqual({ key: 'value' }); expect(subscription.hash).toBe('hash'); expect(subscription.clientRequestIds.size).toBe(0); });
get hasPending() { /* Although the pending map is bucketed by recordingId, the bucket will always be created with a single item in it so we can assume that if a bucket exists, then it has items in it. */ return this.pending.size > 0; }
it('can delete nonexistent request for one client', function() { const subscription = new Subscription( 'className', { key: 'value' }, 'hash' ); subscription.addClientSubscription(1, 1); subscription.deleteClientSubscription(1, 2); expect(logger.error).toHaveBeenCalled(); expect(subscription.clientRequestIds.size).toBe(1); expect(subscription.clientRequestIds.get(1)).toEqual([1]); });
it('can delete subscription information', function() { const subscription = {}; const fields = ['test']; const subscriptionInfo = { subscription: subscription, fields: fields, }; const client = new Client(1, {}); client.addSubscriptionInfo(1, subscriptionInfo); client.deleteSubscriptionInfo(1); expect(client.subscriptionInfos.size).toBe(0); });
/** * Get count of all registered nodes */ count() { return this.nodes.size; }
get hasPending() { /* Although the pending map is bucketed by recordingId, the bucket will always be created with a single item in it so we can assume that if a bucket exists, then it has items in it. */ return this.pending.size > 0; }