Skip to content

Commit f4e558c

Browse files
Add Projection metric registrar
Co-authored-by: Veselin Nikolov <veselin.nikolov@neotechnology.com>
1 parent 3ea1498 commit f4e558c

File tree

6 files changed

+243
-0
lines changed

6 files changed

+243
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.neo4j.gds.projections;
21+
22+
public final class PassthroughProjectionMetric extends ProjectionMetric {
23+
24+
PassthroughProjectionMetric(String projectionMode) {
25+
super(projectionMode);
26+
}
27+
28+
@Override
29+
public void start() {}
30+
31+
@Override
32+
public void failed() {}
33+
34+
@Override
35+
public void close() {}
36+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.neo4j.gds.projections;
21+
22+
/**
23+
* No-op metrics registrar; to be used when metrics are not enabled in Neo4j.
24+
*/
25+
public class PassthroughProjectionMetricRegistrar implements ProjectionMetricRegistrar {
26+
27+
@Override
28+
public ProjectionMetric create(String projectionMode) {
29+
return new PassthroughProjectionMetric(projectionMode);
30+
}
31+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.neo4j.gds.projections;
21+
22+
public abstract class ProjectionMetric implements AutoCloseable {
23+
24+
protected final String projectionMode;
25+
26+
protected ProjectionMetric(String projectionMode) {
27+
this.projectionMode = projectionMode;
28+
}
29+
30+
public abstract void start();
31+
32+
public abstract void failed();
33+
34+
@Override
35+
public abstract void close();
36+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.neo4j.gds.projections;
21+
22+
public interface ProjectionMetricRegistrar {
23+
24+
ProjectionMetric create(String projectionMode);
25+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.neo4j.gds.projections;
21+
22+
public class ProjectionMetricsService {
23+
24+
private final ProjectionMetricRegistrar metricRegistrar;
25+
26+
public ProjectionMetricsService(ProjectionMetricRegistrar metricRegistrar) {
27+
this.metricRegistrar = metricRegistrar;
28+
}
29+
30+
public ProjectionMetric createNative() {
31+
return metricRegistrar.create("native");
32+
}
33+
public ProjectionMetric createCypher() {
34+
return metricRegistrar.create("cypher");
35+
}
36+
public ProjectionMetric createCypherV2() {
37+
return metricRegistrar.create("cypherV2");
38+
}
39+
40+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.neo4j.gds.projections;
21+
22+
import org.junit.jupiter.api.Test;
23+
24+
import static org.mockito.Mockito.mock;
25+
import static org.mockito.Mockito.times;
26+
import static org.mockito.Mockito.verify;
27+
import static org.mockito.Mockito.verifyNoMoreInteractions;
28+
29+
class ProjectionMetricsServiceTest {
30+
31+
@Test
32+
void shouldCreateNativeProjectionMetric() {
33+
// given
34+
var registrarMock = mock(ProjectionMetricRegistrar.class);
35+
var metricsService = new ProjectionMetricsService(registrarMock);
36+
37+
// when
38+
metricsService.createNative();
39+
40+
// then
41+
verify(registrarMock, times(1)).create("native");
42+
verifyNoMoreInteractions(registrarMock);
43+
}
44+
45+
@Test
46+
void shouldCreateCypherProjectionMetric() {
47+
// given
48+
var registrarMock = mock(ProjectionMetricRegistrar.class);
49+
var metricsService = new ProjectionMetricsService(registrarMock);
50+
51+
// when
52+
metricsService.createCypher();
53+
54+
// then
55+
verify(registrarMock, times(1)).create("cypher");
56+
verifyNoMoreInteractions(registrarMock);
57+
}
58+
59+
@Test
60+
void shouldCreateCypherV2ProjectionMetric() {
61+
// given
62+
var registrarMock = mock(ProjectionMetricRegistrar.class);
63+
var metricsService = new ProjectionMetricsService(registrarMock);
64+
65+
// when
66+
metricsService.createCypherV2();
67+
68+
// then
69+
verify(registrarMock, times(1)).create("cypherV2");
70+
verifyNoMoreInteractions(registrarMock);
71+
}
72+
73+
74+
75+
}

0 commit comments

Comments
 (0)