-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
CsvInputBatchImportIT.java
637 lines (587 loc) · 27.4 KB
/
CsvInputBatchImportIT.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
/*
* Copyright (c) 2002-2018 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.unsafe.impl.batchimport.input.csv;
import org.junit.Rule;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetTime;
import java.time.Period;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalQueries;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.TreeMap;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Function;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.Transaction;
import org.neo4j.helpers.collection.Pair;
import org.neo4j.kernel.api.ReadOperations;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.logging.NullLogService;
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine;
import org.neo4j.kernel.impl.store.NeoStores;
import org.neo4j.kernel.impl.store.TokenStore;
import org.neo4j.kernel.impl.store.format.RecordFormatSelector;
import org.neo4j.kernel.impl.util.AutoCreatingHashMap;
import org.neo4j.kernel.internal.GraphDatabaseAPI;
import org.neo4j.logging.LogTimeZone;
import org.neo4j.storageengine.api.Token;
import org.neo4j.test.TestGraphDatabaseFactory;
import org.neo4j.test.rule.TestDirectory;
import org.neo4j.test.rule.fs.DefaultFileSystemRule;
import org.neo4j.unsafe.impl.batchimport.AdditionalInitialIds;
import org.neo4j.unsafe.impl.batchimport.BatchImporter;
import org.neo4j.unsafe.impl.batchimport.Configuration;
import org.neo4j.unsafe.impl.batchimport.ParallelBatchImporter;
import org.neo4j.unsafe.impl.batchimport.input.InputEntity;
import org.neo4j.unsafe.impl.batchimport.input.Collector;
import org.neo4j.unsafe.impl.batchimport.input.Group;
import org.neo4j.unsafe.impl.batchimport.input.Input;
import org.neo4j.values.storable.PointValue;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static java.lang.String.format;
import static java.lang.System.currentTimeMillis;
import static java.nio.charset.Charset.defaultCharset;
import static org.neo4j.graphdb.factory.GraphDatabaseSettings.db_timezone;
import static org.neo4j.helpers.collection.Iterators.asSet;
import static org.neo4j.kernel.impl.util.AutoCreatingHashMap.nested;
import static org.neo4j.kernel.impl.util.AutoCreatingHashMap.values;
import static org.neo4j.register.Registers.newDoubleLongRegister;
import static org.neo4j.unsafe.impl.batchimport.ImportLogic.NO_MONITOR;
import static org.neo4j.unsafe.impl.batchimport.input.Collectors.silentBadCollector;
import static org.neo4j.unsafe.impl.batchimport.input.InputEntityDecorators.NO_DECORATOR;
import static org.neo4j.unsafe.impl.batchimport.input.csv.Configuration.COMMAS;
import static org.neo4j.unsafe.impl.batchimport.input.csv.DataFactories.data;
import static org.neo4j.unsafe.impl.batchimport.input.csv.DataFactories.datas;
import static org.neo4j.unsafe.impl.batchimport.input.csv.DataFactories.defaultFormatNodeFileHeader;
import static org.neo4j.unsafe.impl.batchimport.input.csv.DataFactories.defaultFormatRelationshipFileHeader;
import static org.neo4j.unsafe.impl.batchimport.staging.ExecutionMonitors.invisible;
public class CsvInputBatchImportIT
{
/** Don't support these counts at the moment so don't compute them */
private static final boolean COMPUTE_DOUBLE_SIDED_RELATIONSHIP_COUNTS = false;
private String nameOf( InputEntity node )
{
return (String) node.properties()[1];
}
private int indexOf( InputEntity node )
{
return Integer.parseInt(((String) node.properties()[1]).split( "\\s" )[1] ) ;
}
@Rule
public final TestDirectory directory = TestDirectory.testDirectory();
@Rule
public final DefaultFileSystemRule fileSystemRule = new DefaultFileSystemRule();
private final long seed = currentTimeMillis();
private final Random random = new Random( seed );
private static final Supplier<ZoneId> testDefaultTimeZone = () -> ZoneId.of( "Asia/Shanghai" );
@Test
public void shouldImportDataComingFromCsvFiles() throws Exception
{
// GIVEN
Config dbConfig = Config.builder().withSetting( db_timezone, LogTimeZone.SYSTEM.name() ).build();
BatchImporter importer = new ParallelBatchImporter( directory.graphDbDir(), fileSystemRule.get(), null,
smallBatchSizeConfig(), NullLogService.getInstance(), invisible(), AdditionalInitialIds.EMPTY, dbConfig,
RecordFormatSelector.defaultFormat(), NO_MONITOR );
List<InputEntity> nodeData = randomNodeData();
List<InputEntity> relationshipData = randomRelationshipData( nodeData );
// WHEN
boolean success = false;
try
{
importer.doImport( csv( nodeDataAsFile( nodeData ), relationshipDataAsFile( relationshipData ),
IdType.STRING, lowBufferSize( COMMAS ), silentBadCollector( 0 ) ) );
// THEN
verifyImportedData( nodeData, relationshipData );
success = true;
}
finally
{
if ( !success )
{
System.err.println( "Seed " + seed );
}
}
}
public static Input csv( File nodes, File relationships, IdType idType,
org.neo4j.unsafe.impl.batchimport.input.csv.Configuration configuration, Collector badCollector )
{
return new CsvInput(
datas( data( NO_DECORATOR, defaultCharset(), nodes ) ),
defaultFormatNodeFileHeader( testDefaultTimeZone ),
datas( data( NO_DECORATOR, defaultCharset(), relationships ) ),
defaultFormatRelationshipFileHeader( testDefaultTimeZone ),
idType,
configuration,
badCollector );
}
private static org.neo4j.unsafe.impl.batchimport.input.csv.Configuration lowBufferSize(
org.neo4j.unsafe.impl.batchimport.input.csv.Configuration actual )
{
return new org.neo4j.unsafe.impl.batchimport.input.csv.Configuration.Overridden( actual )
{
@Override
public int bufferSize()
{
return 10_000;
}
};
}
// ======================================================
// Below is code for generating import data
// ======================================================
private List<InputEntity> randomNodeData()
{
List<InputEntity> nodes = new ArrayList<>();
for ( int i = 0; i < 300; i++ )
{
InputEntity node = new InputEntity();
node.id( UUID.randomUUID().toString(), Group.GLOBAL );
node.property( "name", "Node " + i );
node.property( "point", "\" { x : -4.2, y : " + i + ", crs: WGS-84 } \"" );
node.property( "date", LocalDate.of( 2018, i % 12 + 1, i % 28 + 1 ) );
node.property( "time", OffsetTime.of( 1, i % 60, 0, 0, ZoneOffset.ofHours( 9 ) ) );
node.property( "dateTime",
ZonedDateTime.of( 2011, 9, 11, 8, i % 60, 0, 0, ZoneId.of( "Europe/Stockholm" ) ) );
node.property( "dateTime2",
LocalDateTime.of( 2011, 9, 11, 8, i % 60, 0, 0 ) ); // No zone specified
node.property( "localTime", LocalTime.of( 1, i % 60, 0 ) );
node.property( "localDateTime", LocalDateTime.of( 2011, 9, 11, 8, i % 60 ) );
node.property( "duration", Period.of( 2, -3, i % 30 ) );
node.labels( randomLabels( random ) );
nodes.add( node );
}
return nodes;
}
private String[] randomLabels( Random random )
{
String[] labels = new String[random.nextInt( 3 )];
for ( int i = 0; i < labels.length; i++ )
{
labels[i] = "Label" + random.nextInt( 4 );
}
return labels;
}
private Configuration smallBatchSizeConfig()
{
return new Configuration()
{
@Override
public int batchSize()
{
return 100;
}
@Override
public int denseNodeThreshold()
{
return 5;
}
};
}
private File relationshipDataAsFile( List<InputEntity> relationshipData ) throws IOException
{
File file = directory.file( "relationships.csv" );
try ( Writer writer = fileSystemRule.get().openAsWriter( file, StandardCharsets.UTF_8, false ) )
{
// Header
println( writer, ":start_id,:end_id,:type" );
// Data
for ( InputEntity relationship : relationshipData )
{
println( writer, relationship.startId() + "," + relationship.endId() + "," + relationship.stringType );
}
}
return file;
}
private File nodeDataAsFile( List<InputEntity> nodeData ) throws IOException
{
File file = directory.file( "nodes.csv" );
try ( Writer writer = fileSystemRule.get().openAsWriter( file, StandardCharsets.UTF_8, false ) )
{
// Header
println( writer, "id:ID,name,point:Point,date:Date,time:Time,dateTime:DateTime,dateTime2:DateTime,localTime:LocalTime," +
"localDateTime:LocalDateTime,duration:Duration,some-labels:LABEL" );
// Data
for ( InputEntity node : nodeData )
{
String csvLabels = csvLabels( node.labels() );
StringBuilder sb = new StringBuilder( node.id() + "," );
for ( int i = 0; i < node.propertyCount(); i++ )
{
sb.append( node.propertyValue( i ) + "," );
}
sb.append( (csvLabels != null && csvLabels.length() > 0 ? csvLabels : "") );
println( writer, sb.toString() );
}
}
return file;
}
private String csvLabels( String[] labels )
{
if ( labels == null || labels.length == 0 )
{
return null;
}
StringBuilder builder = new StringBuilder();
for ( String label : labels )
{
builder.append( builder.length() > 0 ? ";" : "" ).append( label );
}
return builder.toString();
}
private void println( Writer writer, String string ) throws IOException
{
writer.write( string + "\n" );
}
private List<InputEntity> randomRelationshipData( List<InputEntity> nodeData )
{
List<InputEntity> relationships = new ArrayList<>();
for ( int i = 0; i < 1000; i++ )
{
InputEntity relationship = new InputEntity();
relationship.startId( nodeData.get( random.nextInt( nodeData.size() ) ).id(), Group.GLOBAL );
relationship.endId( nodeData.get( random.nextInt( nodeData.size() ) ).id(), Group.GLOBAL );
relationship.type( "TYPE_" + random.nextInt( 3 ) );
relationships.add( relationship );
}
return relationships;
}
// ======================================================
// Below is code for verifying the imported data
// ======================================================
private void verifyImportedData( List<InputEntity> nodeData,
List<InputEntity> relationshipData )
{
// Build up expected data for the verification below
Map<String/*id*/, InputEntity> expectedNodes = new HashMap<>();
Map<String,String[]> expectedNodeNames = new HashMap<>();
Map<String, Map<String,Consumer<Object>>> expectedNodePropertyVerifiers = new HashMap<>();
Map<String/*start node name*/, Map<String/*end node name*/, Map<String, AtomicInteger>>> expectedRelationships =
new AutoCreatingHashMap<>( nested( String.class, nested( String.class, values( AtomicInteger.class ) ) ) );
Map<String, AtomicLong> expectedNodeCounts = new AutoCreatingHashMap<>( values( AtomicLong.class ) );
Map<String, Map<String, Map<String, AtomicLong>>> expectedRelationshipCounts =
new AutoCreatingHashMap<>( nested( String.class, nested( String.class, values( AtomicLong.class ) ) ) );
buildUpExpectedData( nodeData, relationshipData, expectedNodes, expectedNodeNames, expectedNodePropertyVerifiers,
expectedRelationships, expectedNodeCounts, expectedRelationshipCounts );
// Do the verification
GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase( directory.graphDbDir() );
try ( Transaction tx = db.beginTx() )
{
// Verify nodes
for ( Node node : db.getAllNodes() )
{
String name = (String) node.getProperty( "name" );
String[] labels = expectedNodeNames.remove( name );
assertEquals( asSet( labels ), names( node.getLabels() ) );
// Verify node properties
Map<String,Consumer<Object>> expectedPropertyVerifiers = expectedNodePropertyVerifiers.remove( name );
Map<String,Object> actualProperties = node.getAllProperties();
actualProperties.remove( "id" ); // The id does not exist in expected properties
for ( Map.Entry actualProperty : actualProperties.entrySet() )
{
Consumer v = expectedPropertyVerifiers.get( actualProperty.getKey() );
if ( v != null )
{
v.accept( actualProperty.getValue() );
}
}
}
assertEquals( 0, expectedNodeNames.size() );
// Verify relationships
for ( Relationship relationship : db.getAllRelationships() )
{
String startNodeName = (String) relationship.getStartNode().getProperty( "name" );
Map<String, Map<String, AtomicInteger>> inner = expectedRelationships.get( startNodeName );
String endNodeName = (String) relationship.getEndNode().getProperty( "name" );
Map<String, AtomicInteger> innerInner = inner.get( endNodeName );
String type = relationship.getType().name();
int countAfterwards = innerInner.get( type ).decrementAndGet();
assertThat( countAfterwards, greaterThanOrEqualTo( 0 ) );
if ( countAfterwards == 0 )
{
innerInner.remove( type );
if ( innerInner.isEmpty() )
{
inner.remove( endNodeName );
if ( inner.isEmpty() )
{
expectedRelationships.remove( startNodeName );
}
}
}
}
assertEquals( 0, expectedRelationships.size() );
// Verify counts, TODO how to get counts store other than this way?
NeoStores neoStores = ((GraphDatabaseAPI)db).getDependencyResolver().resolveDependency(
RecordStorageEngine.class ).testAccessNeoStores();
Function<String, Integer> labelTranslationTable =
translationTable( neoStores.getLabelTokenStore(), ReadOperations.ANY_LABEL );
for ( Pair<Integer,Long> count : allNodeCounts( labelTranslationTable, expectedNodeCounts ) )
{
assertEquals( "Label count mismatch for label " + count.first(),
count.other().longValue(),
neoStores.getCounts()
.nodeCount( count.first().intValue(), newDoubleLongRegister() )
.readSecond() );
}
Function<String, Integer> relationshipTypeTranslationTable =
translationTable( neoStores.getRelationshipTypeTokenStore(), ReadOperations.ANY_RELATIONSHIP_TYPE );
for ( Pair<RelationshipCountKey,Long> count : allRelationshipCounts( labelTranslationTable,
relationshipTypeTranslationTable, expectedRelationshipCounts ) )
{
RelationshipCountKey key = count.first();
assertEquals( "Label count mismatch for label " + key,
count.other().longValue(),
neoStores.getCounts()
.relationshipCount( key.startLabel, key.type, key.endLabel, newDoubleLongRegister() )
.readSecond() );
}
tx.success();
}
finally
{
db.shutdown();
}
}
private static class RelationshipCountKey
{
private final int startLabel;
private final int type;
private final int endLabel;
RelationshipCountKey( int startLabel, int type, int endLabel )
{
this.startLabel = startLabel;
this.type = type;
this.endLabel = endLabel;
}
@Override
public String toString()
{
return format( "[start:%d, type:%d, end:%d]", startLabel, type, endLabel );
}
}
private Iterable<Pair<RelationshipCountKey,Long>> allRelationshipCounts(
Function<String, Integer> labelTranslationTable,
Function<String, Integer> relationshipTypeTranslationTable,
Map<String, Map<String, Map<String, AtomicLong>>> counts )
{
Collection<Pair<RelationshipCountKey,Long>> result = new ArrayList<>();
for ( Map.Entry<String, Map<String, Map<String, AtomicLong>>> startLabel : counts.entrySet() )
{
for ( Map.Entry<String, Map<String, AtomicLong>> type : startLabel.getValue().entrySet() )
{
for ( Map.Entry<String, AtomicLong> endLabel : type.getValue().entrySet() )
{
RelationshipCountKey key = new RelationshipCountKey(
labelTranslationTable.apply( startLabel.getKey() ),
relationshipTypeTranslationTable.apply( type.getKey() ),
labelTranslationTable.apply( endLabel.getKey() ) );
result.add( Pair.of( key, endLabel.getValue().longValue() ) );
}
}
}
return result;
}
private Iterable<Pair<Integer,Long>> allNodeCounts( Function<String, Integer> labelTranslationTable,
Map<String, AtomicLong> counts )
{
Collection<Pair<Integer,Long>> result = new ArrayList<>();
for ( Map.Entry<String, AtomicLong> count : counts.entrySet() )
{
result.add( Pair.of( labelTranslationTable.apply( count.getKey() ), count.getValue().get() ) );
}
counts.put( null, new AtomicLong( counts.size() ) );
return result;
}
private Function<String, Integer> translationTable( TokenStore<?, ?> tokenStore, final int anyValue )
{
final Map<String, Integer> translationTable = new HashMap<>();
for ( Token token : tokenStore.getTokens( Integer.MAX_VALUE ) )
{
translationTable.put( token.name(), token.id() );
}
return from -> from == null ? anyValue : translationTable.get( from );
}
private Set<String> names( Iterable<Label> labels )
{
Set<String> names = new HashSet<>();
for ( Label label : labels )
{
names.add( label.name() );
}
return names;
}
private void buildUpExpectedData(
List<InputEntity> nodeData,
List<InputEntity> relationshipData,
Map<String, InputEntity> expectedNodes,
Map<String, String[]> expectedNodeNames,
Map<String, Map<String,Consumer<Object>>> expectedNodePropertyVerifiers,
Map<String, Map<String, Map<String, AtomicInteger>>> expectedRelationships,
Map<String, AtomicLong> nodeCounts,
Map<String, Map<String, Map<String, AtomicLong>>> relationshipCounts )
{
for ( InputEntity node : nodeData )
{
expectedNodes.put( (String) node.id(), node );
expectedNodeNames.put( nameOf( node ), node.labels() );
// Build default verifiers for all the properties that compares the property value using equals
assert node.hasIntPropertyKeyIds == false;
Map<String,Consumer<Object>> propertyVerifiers = new TreeMap<>();
for ( int i = 0; i < node.propertyCount(); i++ )
{
final Object expectedValue = node.propertyValue( i );
Consumer verify;
if ( expectedValue instanceof TemporalAmount )
{
// Since there is no straightforward comparison for TemporalAmount we add it to a reference
// point in time and compare the result
verify = actualValue ->
{
LocalDateTime referenceTemporal = LocalDateTime.of( 0, 1, 1, 0, 0 );
LocalDateTime expected = referenceTemporal.plus( (TemporalAmount) expectedValue );
LocalDateTime actual = referenceTemporal.plus( (TemporalAmount) actualValue );
assertEquals( expected, actual );
};
}
else if ( expectedValue instanceof Temporal )
{
final LocalDate expectedDate = ((Temporal) expectedValue).query( TemporalQueries.localDate() );
final LocalTime expectedTime = ((Temporal) expectedValue).query( TemporalQueries.localTime() );
final ZoneId expectedZoneId = ((Temporal) expectedValue).query( TemporalQueries.zone() );
verify = actualValue ->
{
LocalDate actualDate = ((Temporal) actualValue).query( TemporalQueries.localDate() );
LocalTime actualTime = ((Temporal) actualValue).query( TemporalQueries.localTime() );
ZoneId actualZoneId = ((Temporal) actualValue).query( TemporalQueries.zone() );
assertEquals( expectedDate, actualDate );
assertEquals( expectedTime, actualTime );
if ( expectedZoneId == null )
{
if ( actualZoneId != null )
{
// If the actual value is zoned it should have the default zone
assertEquals( testDefaultTimeZone.get(), actualZoneId );
}
}
else
{
assertEquals( expectedZoneId, actualZoneId );
}
};
}
else
{
verify = actualValue ->
{
assertEquals( expectedValue, actualValue );
};
}
propertyVerifiers.put( (String) node.propertyKey( i ), verify );
}
// Special verifier for point property
Consumer verifyPoint = actualValue ->
{
// The y-coordinate should match the node number
PointValue v = (PointValue) actualValue;
double actualY = v.getCoordinates().get( 0 ).getCoordinate().get( 1 );
double expectedY = indexOf( node );
String message = actualValue.toString() + " does not have y=" + expectedY;
assertEquals( message, expectedY, actualY, 0.1 );
};
propertyVerifiers.put( "point", verifyPoint );
expectedNodePropertyVerifiers.put( nameOf( node ), propertyVerifiers );
countNodeLabels( nodeCounts, node.labels() );
}
for ( InputEntity relationship : relationshipData )
{
// Expected relationship counts per node, type and direction
InputEntity startNode = expectedNodes.get( relationship.startId() );
InputEntity endNode = expectedNodes.get( relationship.endId() );
{
expectedRelationships.get( nameOf( startNode ) )
.get( nameOf( endNode ) )
.get( relationship.stringType )
.incrementAndGet();
}
// Expected counts per start/end node label ids
// Let's do what CountsState#addRelationship does, roughly
relationshipCounts.get( null ).get( null ).get( null ).incrementAndGet();
relationshipCounts.get( null ).get( relationship.stringType ).get( null ).incrementAndGet();
for ( String startNodeLabelName : asSet( startNode.labels() ) )
{
Map<String, Map<String, AtomicLong>> startLabelCounts = relationshipCounts.get( startNodeLabelName );
startLabelCounts.get( null ).get( null ).incrementAndGet();
Map<String, AtomicLong> typeCounts = startLabelCounts.get( relationship.stringType );
typeCounts.get( null ).incrementAndGet();
if ( COMPUTE_DOUBLE_SIDED_RELATIONSHIP_COUNTS )
{
for ( String endNodeLabelName : asSet( endNode.labels() ) )
{
startLabelCounts.get( null ).get( endNodeLabelName ).incrementAndGet();
typeCounts.get( endNodeLabelName ).incrementAndGet();
}
}
}
for ( String endNodeLabelName : asSet( endNode.labels() ) )
{
relationshipCounts.get( null ).get( null ).get( endNodeLabelName ).incrementAndGet();
relationshipCounts.get( null ).get( relationship.stringType ).get( endNodeLabelName ).incrementAndGet();
}
}
}
private void countNodeLabels( Map<String, AtomicLong> nodeCounts, String[] labels )
{
Set<String> seen = new HashSet<>();
for ( String labelName : labels )
{
if ( seen.add( labelName ) )
{
nodeCounts.get( labelName ).incrementAndGet();
}
}
}
}