2020package org .neo4j .gds .hdbscan ;
2121
2222import com .carrotsearch .hppc .BitSet ;
23+ import org .assertj .core .api .Assertions ;
2324import org .assertj .core .data .Offset ;
2425import org .junit .jupiter .api .Test ;
2526import org .neo4j .gds .collections .ha .HugeDoubleArray ;
2627import org .neo4j .gds .collections .ha .HugeLongArray ;
28+ import org .neo4j .gds .compat .TestLog ;
29+ import org .neo4j .gds .core .concurrency .Concurrency ;
30+ import org .neo4j .gds .core .utils .logging .LoggerForProgressTrackingAdapter ;
31+ import org .neo4j .gds .core .utils .progress .EmptyTaskRegistryFactory ;
32+ import org .neo4j .gds .core .utils .progress .tasks .ProgressTracker ;
33+ import org .neo4j .gds .core .utils .progress .tasks .TaskProgressTracker ;
34+ import org .neo4j .gds .logging .GdsTestLog ;
2735
2836import static org .assertj .core .api .Assertions .assertThat ;
37+ import static org .neo4j .gds .assertj .Extractors .removingThreadId ;
38+ import static org .neo4j .gds .assertj .Extractors .replaceTimings ;
2939
3040class LabellingTest {
3141
@@ -40,7 +50,7 @@ void clusterStability() {
4050 var maximumClusterId = 6 ;
4151
4252 var condensedTree = new CondensedTree (root , parent , lambda , size , maximumClusterId , nodeCount );
43- var stabilityStep = new LabellingStep (condensedTree , nodeCount );
53+ var stabilityStep = new LabellingStep (condensedTree , nodeCount , ProgressTracker . NULL_TRACKER );
4454
4555 var stabilities = stabilityStep .computeStabilities ();
4656
@@ -66,7 +76,7 @@ void clusterStabilityBiggerTest() {
6676
6777 var condensedTree = new CondensedTree (root , parent , lambda , size , maximumClusterId , nodeCount );
6878
69- var stabilityStep = new LabellingStep (condensedTree , nodeCount );
79+ var stabilityStep = new LabellingStep (condensedTree , nodeCount , ProgressTracker . NULL_TRACKER );
7080
7181 var stabilities = stabilityStep .computeStabilities ();
7282
@@ -102,7 +112,7 @@ void clusterSelectionOfChildClusters() {
102112 var stabilities = HugeDoubleArray .of (3. , 4. , 5. );
103113
104114 var condensedTree = new CondensedTree (root , parent , lambda , size , maximumClusterId , nodeCount );
105- var stabilityStep = new LabellingStep (condensedTree , nodeCount );
115+ var stabilityStep = new LabellingStep (condensedTree , nodeCount , ProgressTracker . NULL_TRACKER );
106116
107117 var selectedClusters = stabilityStep .selectedClusters (stabilities );
108118
@@ -133,7 +143,7 @@ void clusterSelectionOfParentCluster() {
133143 var stabilities = HugeDoubleArray .of (10. , 4. , 5. );
134144
135145 var condensedTree = new CondensedTree (root , parent , lambda , size , maximumClusterId , nodeCount );
136- var stabilityStep = new LabellingStep (condensedTree , nodeCount );
146+ var stabilityStep = new LabellingStep (condensedTree , nodeCount , ProgressTracker . NULL_TRACKER );
137147
138148 var selectedClusters = stabilityStep .selectedClusters (stabilities );
139149
@@ -164,7 +174,7 @@ void labelling() {
164174 // selects cluster `11`
165175 selectedClusters .set (4 );
166176
167- var stabilityStep = new LabellingStep (condensedTree , nodeCount );
177+ var stabilityStep = new LabellingStep (condensedTree , nodeCount , ProgressTracker . NULL_TRACKER );
168178
169179 var labels = stabilityStep .computeLabels (selectedClusters );
170180
@@ -195,11 +205,57 @@ void labellingWhenAllClustersAreSelected() {
195205 var selectedClusters = new BitSet (5 );
196206 selectedClusters .set (0 , 5 );
197207
198- var stabilityStep = new LabellingStep (condensedTree , nodeCount );
208+ var stabilityStep = new LabellingStep (condensedTree , nodeCount , ProgressTracker . NULL_TRACKER );
199209
200210 var labels = stabilityStep .computeLabels (selectedClusters );
201211
202212 assertThat (labels .size ()).isEqualTo (nodeCount );
203213 assertThat (labels .toArray ()).containsOnly (0L );
204214 }
215+
216+ @ Test
217+ void shouldLogProgress (){
218+ var nodeCount = 4 ;
219+ var root = 4 ;
220+
221+ var parent = HugeLongArray .of (5 , 5 , 6 , 6 , 0 , 4 , 4 );
222+ var lambda = HugeDoubleArray .of (10 , 10 , 11 , 11 , 0 , 12 , 12 );
223+ var size = HugeLongArray .of (4 , 2 , 2 );
224+ var maximumClusterId = 6 ;
225+
226+ var condensedTree = new CondensedTree (root , parent , lambda , size , maximumClusterId , nodeCount );
227+
228+ var progressTask = HDBScanProgressTrackerCreator .labellingTask ("foo" ,nodeCount );
229+ var log = new GdsTestLog ();
230+ var progressTracker = new TaskProgressTracker (progressTask , new LoggerForProgressTrackingAdapter (log ), new Concurrency (1 ), EmptyTaskRegistryFactory .INSTANCE );
231+
232+ new LabellingStep (condensedTree , nodeCount , progressTracker ).labels ();
233+
234+ Assertions .assertThat (log .getMessages (TestLog .INFO ))
235+ .extracting (removingThreadId ())
236+ .extracting (replaceTimings ())
237+ .containsExactly (
238+ "foo :: Start" ,
239+ "foo :: Stability calculation :: Start" ,
240+ "foo :: Stability calculation 33%" ,
241+ "foo :: Stability calculation 66%" ,
242+ "foo :: Stability calculation 100%" ,
243+ "foo :: Stability calculation :: Finished" ,
244+ "foo :: cluster selection :: Start" ,
245+ "foo :: cluster selection 33%" ,
246+ "foo :: cluster selection 66%" ,
247+ "foo :: cluster selection 100%" ,
248+ "foo :: cluster selection :: Finished" ,
249+ "foo :: labelling :: Start" ,
250+ "foo :: labelling 14%" ,
251+ "foo :: labelling 28%" ,
252+ "foo :: labelling 42%" ,
253+ "foo :: labelling 57%" ,
254+ "foo :: labelling 71%" ,
255+ "foo :: labelling 85%" ,
256+ "foo :: labelling 100%" ,
257+ "foo :: labelling :: Finished" ,
258+ "foo :: Finished"
259+ );
260+ }
205261}
0 commit comments