|
19 | 19 | */ |
20 | 20 | package org.neo4j.gds.projection; |
21 | 21 |
|
| 22 | +import com.carrotsearch.hppc.LongHashSet; |
| 23 | +import org.agrona.collections.MutableBoolean; |
22 | 24 | import org.junit.jupiter.api.Test; |
23 | 25 | import org.neo4j.gds.ImmutableRelationshipProjections; |
| 26 | +import org.neo4j.gds.NodeLabel; |
| 27 | +import org.neo4j.gds.NodeProjection; |
24 | 28 | import org.neo4j.gds.NodeProjections; |
25 | 29 | import org.neo4j.gds.Orientation; |
26 | 30 | import org.neo4j.gds.RelationshipProjection; |
27 | 31 | import org.neo4j.gds.RelationshipProjections; |
28 | 32 | import org.neo4j.gds.RelationshipType; |
29 | 33 | import org.neo4j.gds.api.CSRGraphStoreFactory; |
| 34 | +import org.neo4j.gds.api.GraphLoaderContext; |
30 | 35 | import org.neo4j.gds.core.GraphDimensions; |
31 | 36 | import org.neo4j.gds.core.ImmutableGraphDimensions; |
32 | 37 | import org.neo4j.gds.core.concurrency.Concurrency; |
| 38 | +import org.neo4j.gds.core.utils.progress.JobId; |
| 39 | +import org.neo4j.gds.core.utils.progress.TaskRegistry; |
| 40 | +import org.neo4j.gds.core.utils.progress.TaskRegistryFactory; |
| 41 | +import org.neo4j.gds.logging.Log; |
33 | 42 | import org.neo4j.gds.mem.MemoryEstimation; |
34 | 43 | import org.neo4j.gds.mem.MemoryTree; |
35 | 44 |
|
| 45 | +import java.util.Map; |
| 46 | +import java.util.Optional; |
36 | 47 | import java.util.concurrent.atomic.AtomicReference; |
37 | 48 |
|
| 49 | +import static org.assertj.core.api.Assertions.assertThat; |
38 | 50 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 51 | +import static org.mockito.ArgumentMatchers.any; |
| 52 | +import static org.mockito.Mockito.mock; |
| 53 | +import static org.mockito.Mockito.times; |
| 54 | +import static org.mockito.Mockito.verify; |
| 55 | +import static org.mockito.Mockito.when; |
39 | 56 |
|
40 | 57 | class NativeFactoryTest { |
41 | 58 |
|
@@ -142,4 +159,67 @@ void memoryEstimationForMultipleProjections() { |
142 | 159 | assertEquals(12_056_534_400L, estimate.memoryUsage().min); |
143 | 160 | assertEquals(13_667_147_136L, estimate.memoryUsage().max); |
144 | 161 | } |
| 162 | + |
| 163 | + @Test |
| 164 | + void shouldCleanTaskOnValidateFailure(){ |
| 165 | + |
| 166 | + var mockRegistry = mock(TaskRegistry.class); |
| 167 | + |
| 168 | + var mockRegistryFactory = mock(TaskRegistryFactory.class); |
| 169 | + when(mockRegistryFactory.newInstance(any())).thenReturn(mockRegistry); |
| 170 | + var mockgraphLoaderContext = mock(GraphLoaderContext.class); |
| 171 | + when(mockgraphLoaderContext.taskRegistryFactory()).thenReturn(mockRegistryFactory); |
| 172 | + when(mockgraphLoaderContext.log()).thenReturn(Log.noOpLog()); |
| 173 | + |
| 174 | + var labelSet = new LongHashSet(); |
| 175 | + labelSet.add(GraphDimensions.NO_SUCH_LABEL); |
| 176 | + var graphDimensions =ImmutableGraphDimensions.builder() |
| 177 | + .nodeCount(100) |
| 178 | + .nodeLabelTokens(labelSet) |
| 179 | + .build(); |
| 180 | + |
| 181 | + var config = mock(GraphProjectFromStoreConfig.class); |
| 182 | + when(config.relationshipProjections()).thenReturn(new RelationshipProjections() { |
| 183 | + @Override |
| 184 | + public Map<RelationshipType, RelationshipProjection> projections() { |
| 185 | + return Map.of(); |
| 186 | + } |
| 187 | + }); |
| 188 | + |
| 189 | + when(config.nodeProjections()).thenReturn(new NodeProjections() { |
| 190 | + @Override |
| 191 | + public Map<NodeLabel, NodeProjection> projections() { |
| 192 | + return Map.of( |
| 193 | + NodeLabel.of("foo"), new NodeProjection() { |
| 194 | + @Override |
| 195 | + public String label() { |
| 196 | + return "bar"; |
| 197 | + } |
| 198 | + } |
| 199 | + ); |
| 200 | + } |
| 201 | + }); |
| 202 | + |
| 203 | + when(config.logProgress()).thenReturn(true); |
| 204 | + when(config.jobId()).thenReturn(new JobId("foo")); |
| 205 | + when(config.readConcurrency()).thenReturn(new Concurrency(1)); |
| 206 | + |
| 207 | + var nativeFactory = NativeFactory.nativeFactory( |
| 208 | + config, |
| 209 | + mockgraphLoaderContext, |
| 210 | + Optional.of(graphDimensions) |
| 211 | + ); |
| 212 | + |
| 213 | + MutableBoolean failed = new MutableBoolean(false); |
| 214 | + try { |
| 215 | + nativeFactory.build(); |
| 216 | + } catch (Exception ignored){ |
| 217 | + failed.set(true); |
| 218 | + } |
| 219 | + |
| 220 | + assertThat(failed.get()).isTrue(); |
| 221 | + verify(mockRegistry,times(1)).registerTask(any()); |
| 222 | + verify(mockRegistry,times(1)).markCompleted(); |
| 223 | + |
| 224 | + } |
145 | 225 | } |
0 commit comments