Skip to content

Commit

Permalink
Hermes console vue stats (#1703)
Browse files Browse the repository at this point in the history
  • Loading branch information
moscicky authored Aug 17, 2023
1 parent ec27914 commit 9ff4ae7
Show file tree
Hide file tree
Showing 22 changed files with 822 additions and 1 deletion.
46 changes: 46 additions & 0 deletions hermes-api/src/main/java/pl/allegro/tech/hermes/api/Stats.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package pl.allegro.tech.hermes.api;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Objects;

public class Stats {
private final TopicStats topicStats;
private final SubscriptionStats subscriptionStats;

@JsonCreator
public Stats(@JsonProperty("topicStats") TopicStats topicStats, @JsonProperty("subscriptionStats") SubscriptionStats subscriptionStats) {

Check warning on line 13 in hermes-api/src/main/java/pl/allegro/tech/hermes/api/Stats.java

View workflow job for this annotation

GitHub Actions / checkstyle-hermes-api

[checkstyle-hermes-api] hermes-api/src/main/java/pl/allegro/tech/hermes/api/Stats.java#L13 <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck>

Line is longer than 140 characters (found 141).
Raw output
/home/runner/work/hermes/hermes/hermes-api/src/main/java/pl/allegro/tech/hermes/api/Stats.java:13:0: warning: Line is longer than 140 characters (found 141). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
this.topicStats = topicStats;
this.subscriptionStats = subscriptionStats;
}

public TopicStats getTopicStats() {
return topicStats;
}

public SubscriptionStats getSubscriptionStats() {
return subscriptionStats;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;

Check warning on line 28 in hermes-api/src/main/java/pl/allegro/tech/hermes/api/Stats.java

View workflow job for this annotation

GitHub Actions / checkstyle-hermes-api

[checkstyle-hermes-api] hermes-api/src/main/java/pl/allegro/tech/hermes/api/Stats.java#L28 <com.puppycrawl.tools.checkstyle.checks.blocks.NeedBracesCheck>

'if' construct must use '{}'s.
Raw output
/home/runner/work/hermes/hermes/hermes-api/src/main/java/pl/allegro/tech/hermes/api/Stats.java:28:9: warning: 'if' construct must use '{}'s. (com.puppycrawl.tools.checkstyle.checks.blocks.NeedBracesCheck)
if (o == null || getClass() != o.getClass()) return false;

Check warning on line 29 in hermes-api/src/main/java/pl/allegro/tech/hermes/api/Stats.java

View workflow job for this annotation

GitHub Actions / checkstyle-hermes-api

[checkstyle-hermes-api] hermes-api/src/main/java/pl/allegro/tech/hermes/api/Stats.java#L29 <com.puppycrawl.tools.checkstyle.checks.blocks.NeedBracesCheck>

'if' construct must use '{}'s.
Raw output
/home/runner/work/hermes/hermes/hermes-api/src/main/java/pl/allegro/tech/hermes/api/Stats.java:29:9: warning: 'if' construct must use '{}'s. (com.puppycrawl.tools.checkstyle.checks.blocks.NeedBracesCheck)
Stats stats = (Stats) o;
return Objects.equals(topicStats, stats.topicStats) && Objects.equals(subscriptionStats, stats.subscriptionStats);
}

@Override
public int hashCode() {
return Objects.hash(topicStats, subscriptionStats);
}

@Override
public String toString() {
return "Stats{" +

Check warning on line 41 in hermes-api/src/main/java/pl/allegro/tech/hermes/api/Stats.java

View workflow job for this annotation

GitHub Actions / checkstyle-hermes-api

[checkstyle-hermes-api] hermes-api/src/main/java/pl/allegro/tech/hermes/api/Stats.java#L41 <com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck>

'+' should be on a new line.
Raw output
/home/runner/work/hermes/hermes/hermes-api/src/main/java/pl/allegro/tech/hermes/api/Stats.java:41:25: warning: '+' should be on a new line. (com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck)
"topicStats=" + topicStats +

Check warning on line 42 in hermes-api/src/main/java/pl/allegro/tech/hermes/api/Stats.java

View workflow job for this annotation

GitHub Actions / checkstyle-hermes-api

[checkstyle-hermes-api] hermes-api/src/main/java/pl/allegro/tech/hermes/api/Stats.java#L42 <com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck>

'+' should be on a new line.
Raw output
/home/runner/work/hermes/hermes/hermes-api/src/main/java/pl/allegro/tech/hermes/api/Stats.java:42:44: warning: '+' should be on a new line. (com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck)
", subscriptionStats=" + subscriptionStats +

Check warning on line 43 in hermes-api/src/main/java/pl/allegro/tech/hermes/api/Stats.java

View workflow job for this annotation

GitHub Actions / checkstyle-hermes-api

[checkstyle-hermes-api] hermes-api/src/main/java/pl/allegro/tech/hermes/api/Stats.java#L43 <com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck>

'+' should be on a new line.
Raw output
/home/runner/work/hermes/hermes/hermes-api/src/main/java/pl/allegro/tech/hermes/api/Stats.java:43:60: warning: '+' should be on a new line. (com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck)
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package pl.allegro.tech.hermes.api;


import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Objects;

public class SubscriptionStats {
private final long subscriptionCount;
private final long trackingEnabledSubscriptionCount;
private final long avroSubscriptionCount;

@JsonCreator
public SubscriptionStats(
@JsonProperty("subscriptionCount") long subscriptionCount,
@JsonProperty("trackingEnabledSubscriptionCount") long trackingEnabledSubscriptionCount,
@JsonProperty("avroSubscriptionCount") long avroSubscriptionCount) {
this.subscriptionCount = subscriptionCount;
this.trackingEnabledSubscriptionCount = trackingEnabledSubscriptionCount;
this.avroSubscriptionCount = avroSubscriptionCount;
}

public long getSubscriptionCount() {
return subscriptionCount;
}

public long getTrackingEnabledSubscriptionCount() {
return trackingEnabledSubscriptionCount;
}

public long getAvroSubscriptionCount() {
return avroSubscriptionCount;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;

Check warning on line 38 in hermes-api/src/main/java/pl/allegro/tech/hermes/api/SubscriptionStats.java

View workflow job for this annotation

GitHub Actions / checkstyle-hermes-api

[checkstyle-hermes-api] hermes-api/src/main/java/pl/allegro/tech/hermes/api/SubscriptionStats.java#L38 <com.puppycrawl.tools.checkstyle.checks.blocks.NeedBracesCheck>

'if' construct must use '{}'s.
Raw output
/home/runner/work/hermes/hermes/hermes-api/src/main/java/pl/allegro/tech/hermes/api/SubscriptionStats.java:38:9: warning: 'if' construct must use '{}'s. (com.puppycrawl.tools.checkstyle.checks.blocks.NeedBracesCheck)
if (o == null || getClass() != o.getClass()) return false;

Check warning on line 39 in hermes-api/src/main/java/pl/allegro/tech/hermes/api/SubscriptionStats.java

View workflow job for this annotation

GitHub Actions / checkstyle-hermes-api

[checkstyle-hermes-api] hermes-api/src/main/java/pl/allegro/tech/hermes/api/SubscriptionStats.java#L39 <com.puppycrawl.tools.checkstyle.checks.blocks.NeedBracesCheck>

'if' construct must use '{}'s.
Raw output
/home/runner/work/hermes/hermes/hermes-api/src/main/java/pl/allegro/tech/hermes/api/SubscriptionStats.java:39:9: warning: 'if' construct must use '{}'s. (com.puppycrawl.tools.checkstyle.checks.blocks.NeedBracesCheck)
SubscriptionStats that = (SubscriptionStats) o;
return subscriptionCount == that.subscriptionCount && trackingEnabledSubscriptionCount == that.trackingEnabledSubscriptionCount && avroSubscriptionCount == that.avroSubscriptionCount;

Check warning on line 41 in hermes-api/src/main/java/pl/allegro/tech/hermes/api/SubscriptionStats.java

View workflow job for this annotation

GitHub Actions / checkstyle-hermes-api

[checkstyle-hermes-api] hermes-api/src/main/java/pl/allegro/tech/hermes/api/SubscriptionStats.java#L41 <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck>

Line is longer than 140 characters (found 191).
Raw output
/home/runner/work/hermes/hermes/hermes-api/src/main/java/pl/allegro/tech/hermes/api/SubscriptionStats.java:41:0: warning: Line is longer than 140 characters (found 191). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
}

@Override
public int hashCode() {
return Objects.hash(subscriptionCount, trackingEnabledSubscriptionCount, avroSubscriptionCount);
}

@Override
public String toString() {
return "SubscriptionStats{" +

Check warning on line 51 in hermes-api/src/main/java/pl/allegro/tech/hermes/api/SubscriptionStats.java

View workflow job for this annotation

GitHub Actions / checkstyle-hermes-api

[checkstyle-hermes-api] hermes-api/src/main/java/pl/allegro/tech/hermes/api/SubscriptionStats.java#L51 <com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck>

'+' should be on a new line.
Raw output
/home/runner/work/hermes/hermes/hermes-api/src/main/java/pl/allegro/tech/hermes/api/SubscriptionStats.java:51:37: warning: '+' should be on a new line. (com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck)
"subscriptionCount=" + subscriptionCount +

Check warning on line 52 in hermes-api/src/main/java/pl/allegro/tech/hermes/api/SubscriptionStats.java

View workflow job for this annotation

GitHub Actions / checkstyle-hermes-api

[checkstyle-hermes-api] hermes-api/src/main/java/pl/allegro/tech/hermes/api/SubscriptionStats.java#L52 <com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck>

'+' should be on a new line.
Raw output
/home/runner/work/hermes/hermes/hermes-api/src/main/java/pl/allegro/tech/hermes/api/SubscriptionStats.java:52:58: warning: '+' should be on a new line. (com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck)
", trackingEnabledSubscriptionCount=" + trackingEnabledSubscriptionCount +

Check warning on line 53 in hermes-api/src/main/java/pl/allegro/tech/hermes/api/SubscriptionStats.java

View workflow job for this annotation

GitHub Actions / checkstyle-hermes-api

[checkstyle-hermes-api] hermes-api/src/main/java/pl/allegro/tech/hermes/api/SubscriptionStats.java#L53 <com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck>

'+' should be on a new line.
Raw output
/home/runner/work/hermes/hermes/hermes-api/src/main/java/pl/allegro/tech/hermes/api/SubscriptionStats.java:53:90: warning: '+' should be on a new line. (com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck)
", avroSubscriptionCount=" + avroSubscriptionCount +

Check warning on line 54 in hermes-api/src/main/java/pl/allegro/tech/hermes/api/SubscriptionStats.java

View workflow job for this annotation

GitHub Actions / checkstyle-hermes-api

[checkstyle-hermes-api] hermes-api/src/main/java/pl/allegro/tech/hermes/api/SubscriptionStats.java#L54 <com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck>

'+' should be on a new line.
Raw output
/home/runner/work/hermes/hermes/hermes-api/src/main/java/pl/allegro/tech/hermes/api/SubscriptionStats.java:54:68: warning: '+' should be on a new line. (com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck)
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package pl.allegro.tech.hermes.api;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Objects;

public class TopicStats {
private final long topicCount;
private final long ackAllTopicCount;
private final long trackingEnabledTopicCount;
private final long avroTopicCount;

@JsonCreator
public TopicStats(@JsonProperty("topicCount") long topicCount,
@JsonProperty("ackAllTopicCount") long ackAllTopicCount,
@JsonProperty("trackingEnabledTopicCount") long trackingEnabledTopicCount,
@JsonProperty("avroTopicCount") long avroTopicCount) {
this.topicCount = topicCount;
this.ackAllTopicCount = ackAllTopicCount;
this.trackingEnabledTopicCount = trackingEnabledTopicCount;
this.avroTopicCount = avroTopicCount;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;

Check warning on line 27 in hermes-api/src/main/java/pl/allegro/tech/hermes/api/TopicStats.java

View workflow job for this annotation

GitHub Actions / checkstyle-hermes-api

[checkstyle-hermes-api] hermes-api/src/main/java/pl/allegro/tech/hermes/api/TopicStats.java#L27 <com.puppycrawl.tools.checkstyle.checks.blocks.NeedBracesCheck>

'if' construct must use '{}'s.
Raw output
/home/runner/work/hermes/hermes/hermes-api/src/main/java/pl/allegro/tech/hermes/api/TopicStats.java:27:9: warning: 'if' construct must use '{}'s. (com.puppycrawl.tools.checkstyle.checks.blocks.NeedBracesCheck)
if (o == null || getClass() != o.getClass()) return false;

Check warning on line 28 in hermes-api/src/main/java/pl/allegro/tech/hermes/api/TopicStats.java

View workflow job for this annotation

GitHub Actions / checkstyle-hermes-api

[checkstyle-hermes-api] hermes-api/src/main/java/pl/allegro/tech/hermes/api/TopicStats.java#L28 <com.puppycrawl.tools.checkstyle.checks.blocks.NeedBracesCheck>

'if' construct must use '{}'s.
Raw output
/home/runner/work/hermes/hermes/hermes-api/src/main/java/pl/allegro/tech/hermes/api/TopicStats.java:28:9: warning: 'if' construct must use '{}'s. (com.puppycrawl.tools.checkstyle.checks.blocks.NeedBracesCheck)
TopicStats that = (TopicStats) o;
return topicCount == that.topicCount && ackAllTopicCount == that.ackAllTopicCount && trackingEnabledTopicCount == that.trackingEnabledTopicCount && avroTopicCount == that.avroTopicCount;

Check warning on line 30 in hermes-api/src/main/java/pl/allegro/tech/hermes/api/TopicStats.java

View workflow job for this annotation

GitHub Actions / checkstyle-hermes-api

[checkstyle-hermes-api] hermes-api/src/main/java/pl/allegro/tech/hermes/api/TopicStats.java#L30 <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck>

Line is longer than 140 characters (found 194).
Raw output
/home/runner/work/hermes/hermes/hermes-api/src/main/java/pl/allegro/tech/hermes/api/TopicStats.java:30:0: warning: Line is longer than 140 characters (found 194). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
}

@Override
public int hashCode() {
return Objects.hash(topicCount, ackAllTopicCount, trackingEnabledTopicCount, avroTopicCount);
}

@Override
public String toString() {
return "TopicStats{" +

Check warning on line 40 in hermes-api/src/main/java/pl/allegro/tech/hermes/api/TopicStats.java

View workflow job for this annotation

GitHub Actions / checkstyle-hermes-api

[checkstyle-hermes-api] hermes-api/src/main/java/pl/allegro/tech/hermes/api/TopicStats.java#L40 <com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck>

'+' should be on a new line.
Raw output
/home/runner/work/hermes/hermes/hermes-api/src/main/java/pl/allegro/tech/hermes/api/TopicStats.java:40:30: warning: '+' should be on a new line. (com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck)
"topicCount=" + topicCount +

Check warning on line 41 in hermes-api/src/main/java/pl/allegro/tech/hermes/api/TopicStats.java

View workflow job for this annotation

GitHub Actions / checkstyle-hermes-api

[checkstyle-hermes-api] hermes-api/src/main/java/pl/allegro/tech/hermes/api/TopicStats.java#L41 <com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck>

'+' should be on a new line.
Raw output
/home/runner/work/hermes/hermes/hermes-api/src/main/java/pl/allegro/tech/hermes/api/TopicStats.java:41:44: warning: '+' should be on a new line. (com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck)
", ackAllTopicCount=" + ackAllTopicCount +

Check warning on line 42 in hermes-api/src/main/java/pl/allegro/tech/hermes/api/TopicStats.java

View workflow job for this annotation

GitHub Actions / checkstyle-hermes-api

[checkstyle-hermes-api] hermes-api/src/main/java/pl/allegro/tech/hermes/api/TopicStats.java#L42 <com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck>

'+' should be on a new line.
Raw output
/home/runner/work/hermes/hermes/hermes-api/src/main/java/pl/allegro/tech/hermes/api/TopicStats.java:42:58: warning: '+' should be on a new line. (com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck)
", trackingEnabledTopicCount=" + trackingEnabledTopicCount +

Check warning on line 43 in hermes-api/src/main/java/pl/allegro/tech/hermes/api/TopicStats.java

View workflow job for this annotation

GitHub Actions / checkstyle-hermes-api

[checkstyle-hermes-api] hermes-api/src/main/java/pl/allegro/tech/hermes/api/TopicStats.java#L43 <com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck>

'+' should be on a new line.
Raw output
/home/runner/work/hermes/hermes/hermes-api/src/main/java/pl/allegro/tech/hermes/api/TopicStats.java:43:76: warning: '+' should be on a new line. (com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck)
", avroTopicCount=" + avroTopicCount +

Check warning on line 44 in hermes-api/src/main/java/pl/allegro/tech/hermes/api/TopicStats.java

View workflow job for this annotation

GitHub Actions / checkstyle-hermes-api

[checkstyle-hermes-api] hermes-api/src/main/java/pl/allegro/tech/hermes/api/TopicStats.java#L44 <com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck>

'+' should be on a new line.
Raw output
/home/runner/work/hermes/hermes/hermes-api/src/main/java/pl/allegro/tech/hermes/api/TopicStats.java:44:54: warning: '+' should be on a new line. (com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck)
'}';
}

public long getTopicCount() {
return topicCount;
}

public long getAckAllTopicCount() {
return ackAllTopicCount;
}

public long getTrackingEnabledTopicCount() {
return trackingEnabledTopicCount;
}

public long getAvroTopicCount() {
return avroTopicCount;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package pl.allegro.tech.hermes.api.endpoints;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import pl.allegro.tech.hermes.api.Stats;

import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON;

@Path("stats")
public interface StatsEndpoint {
@GET
@Produces(APPLICATION_JSON)
Stats getStats();
}
13 changes: 13 additions & 0 deletions hermes-console-vue/json-server/db.json
Original file line number Diff line number Diff line change
Expand Up @@ -552,5 +552,18 @@
"group": {
"nonAdminCreationEnabled": false
}
},
"stats": {
"topicStats": {
"topicCount": 111,
"ackAllTopicCount": 33,
"trackingEnabledTopicCount": 12,
"avroTopicCount": 95
},
"subscriptionStats": {
"subscriptionCount": 527,
"trackingEnabledSubscriptionCount": 67,
"avroSubscriptionCount": 100
}
}
}
3 changes: 2 additions & 1 deletion hermes-console-vue/json-server/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
"/topics/:topicName/subscriptions/:id/metrics": "/subscriptionsMetrics/:id",
"/topics/:topicName/subscriptions/:id/undelivered": "/subscriptionUndeliveredMessages",
"/topics/:topicName/subscriptions/:id/undelivered/last": "/subscriptionUndeliveredMessages/:id",
"/workload-constraints": "/constraints"
"/workload-constraints": "/constraints",
"/stats": "/stats"
}
5 changes: 5 additions & 0 deletions hermes-console-vue/src/api/hermes-client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
import type { OfflineClientsSource } from '@/api/offline-clients-source';
import type { Owner } from '@/api/owner';
import type { ResponsePromise } from '@/utils/axios-utils';
import type { Stats } from '@/api/stats';
import type { Subscription } from '@/api/subscription';

export function fetchTopic(
Expand Down Expand Up @@ -91,3 +92,7 @@ export function fetchTopicNames(): ResponsePromise<string[]> {
export function fetchGroupNames(): ResponsePromise<string[]> {
return axios.get<string[]>('/groups');
}

export function fetchStats(): ResponsePromise<Stats> {
return axios.get<Stats>(`/stats`);
}
17 changes: 17 additions & 0 deletions hermes-console-vue/src/api/stats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export interface Stats {
topicStats: TopicStats;
subscriptionStats: SubscriptionStats;
}

export interface TopicStats {
topicCount: number;
ackAllTopicCount: number;
trackingEnabledTopicCount: number;
avroTopicCount: number;
}

export interface SubscriptionStats {
subscriptionCount: number;
trackingEnabledSubscriptionCount: number;
avroSubscriptionCount: number;
}
116 changes: 116 additions & 0 deletions hermes-console-vue/src/composables/use-stats/useStats.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { afterEach } from 'vitest';
import { fetchStatsErrorHandler, fetchStatsHandler } from '@/mocks/handlers';
import { setupServer } from 'msw/node';
import { statsResponse } from '@/dummy/stats';
import { useStats } from '@/composables/use-stats/useStats';
import { waitFor } from '@testing-library/vue';

describe('useStats', () => {
const server = setupServer(fetchStatsHandler({ stats: statsResponse }));

afterEach(() => {
server.resetHandlers();
});

it('should fetch stats details from Hermes API', async () => {
// given
server.listen();

// when
const { stats, loading, error } = useStats();

// then
expect(loading.value).toBeTruthy();

await waitFor(() => {
expect(loading.value).toBeFalsy();
expect(error.value.fetchError).toBeNull();
const {
topicCount,
ackAllTopicCount,
ackAllTopicShare,
trackingEnabledTopicCount,
trackingEnabledTopicShare,
avroTopicCount,
avroTopicShare,
subscriptionCount,
trackingEnabledSubscriptionCount,
trackingEnabledSubscriptionShare,
avroSubscriptionCount,
avroSubscriptionShare,
} = stats.value!!;

expect(topicCount).toEqual(statsResponse.topicStats.topicCount);
expect(ackAllTopicCount).toEqual(
statsResponse.topicStats.ackAllTopicCount,
);
expect(ackAllTopicShare).toBeCloseTo(
share(
statsResponse.topicStats.ackAllTopicCount,
statsResponse.topicStats.topicCount,
),
0.001,
);
expect(avroTopicCount).toEqual(statsResponse.topicStats.avroTopicCount);
expect(avroTopicShare).toBeCloseTo(
share(
statsResponse.topicStats.avroTopicCount,
statsResponse.topicStats.topicCount,
),
0.001,
);
expect(trackingEnabledTopicCount).toEqual(
statsResponse.topicStats.trackingEnabledTopicCount,
);
expect(trackingEnabledTopicShare).toBeCloseTo(
share(
statsResponse.topicStats.trackingEnabledTopicCount,
statsResponse.topicStats.topicCount,
),
0.001,
);
expect(subscriptionCount).toEqual(
statsResponse.subscriptionStats.subscriptionCount,
);
expect(avroSubscriptionCount).toEqual(
statsResponse.subscriptionStats.avroSubscriptionCount,
);
expect(avroSubscriptionShare).toBeCloseTo(
share(
statsResponse.subscriptionStats.avroSubscriptionCount,
statsResponse.subscriptionStats.subscriptionCount,
),
0.001,
);
expect(trackingEnabledSubscriptionCount).toEqual(
statsResponse.subscriptionStats.trackingEnabledSubscriptionCount,
);
expect(trackingEnabledSubscriptionShare).toBeCloseTo(
share(
statsResponse.subscriptionStats.trackingEnabledSubscriptionCount,
statsResponse.subscriptionStats.subscriptionCount,
),
0.001,
);
});
});

it('should set error to true on stats endpoint failure', async () => {
// given
server.use(fetchStatsErrorHandler({ errorCode: 500 }));
server.listen();

// when
const { loading, error } = useStats();

// then
await waitFor(() => {
expect(loading.value).toBe(false);
expect(error.value.fetchError).not.toBeNull();
});
});
});

function share(numerator: number, denominator: number): number {
return (numerator / denominator) * 100;
}
Loading

0 comments on commit 9ff4ae7

Please sign in to comment.