Skip to content

Commit 9e9ef23

Browse files
committed
Add count method to TaskStore
1 parent 3786c01 commit 9e9ef23

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

core/src/main/java/org/neo4j/gds/core/utils/progress/EmptyTaskStore.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,9 @@ public boolean isEmpty() {
5555
return true;
5656
}
5757

58+
@Override
59+
public long tasksCount() {
60+
return 0;
61+
}
62+
5863
}

core/src/main/java/org/neo4j/gds/core/utils/progress/GlobalTaskStore.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,9 @@ public boolean isEmpty() {
8787
.stream()
8888
.allMatch(Map::isEmpty);
8989
}
90+
91+
@Override
92+
public long tasksCount() {
93+
return registeredTasks.values().stream().mapToLong(Map::size).sum();
94+
}
9095
}

core/src/main/java/org/neo4j/gds/core/utils/progress/TaskStore.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,6 @@ public interface TaskStore {
4040
Stream<Task> taskStream();
4141

4242
boolean isEmpty();
43+
44+
long tasksCount();
4345
}

core/src/test/java/org/neo4j/gds/core/utils/progress/GlobalTaskStoreTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,20 @@ void shouldReturnEmptyResultWhenStoreIsEmpty() {
4242
.isNotNull()
4343
.isEmpty();
4444
}
45+
46+
@Test
47+
void shouldCountAcrossUsers() {
48+
var taskStore = new GlobalTaskStore();
49+
taskStore.store("a", new JobId(), Tasks.leaf("v"));
50+
51+
assertThat(taskStore.tasksCount()).isEqualTo(1);
52+
53+
taskStore.store("b", new JobId(), Tasks.leaf("x"));
54+
55+
assertThat(taskStore.tasksCount()).isEqualTo(2);
56+
57+
taskStore.store("b", new JobId(), Tasks.leaf("y"));
58+
59+
assertThat(taskStore.tasksCount()).isEqualTo(3);
60+
}
4561
}

0 commit comments

Comments
 (0)