use of org.neo4j.internal.batchimport.input.Collector in project neo4j by neo4j.
the class EncodingIdMapperTest method shouldReportCollisionsForSameInputId.
@Test
public void shouldReportCollisionsForSameInputId() {
// GIVEN
IdMapper mapper = mapper(new StringEncoder(), Radix.STRING, EncodingIdMapper.NO_MONITOR);
PropertyValueLookup values = values("10", "9", "10");
for (int i = 0; i < 3; i++) {
mapper.put(values.lookupProperty(i, NULL), i, Group.GLOBAL);
}
// WHEN
Collector collector = mock(Collector.class);
mapper.prepare(values, collector, NONE);
// THEN
verify(collector).collectDuplicateNode("10", 2, Group.GLOBAL.name());
verifyNoMoreInteractions(collector);
}
use of org.neo4j.internal.batchimport.input.Collector in project neo4j by neo4j.
the class EncodingIdMapperTest method shouldCopeWithCollisionsBasedOnDifferentInputIds.
@Test
public void shouldCopeWithCollisionsBasedOnDifferentInputIds() {
// GIVEN
EncodingIdMapper.Monitor monitor = mock(EncodingIdMapper.Monitor.class);
Encoder encoder = mock(Encoder.class);
when(encoder.encode(any())).thenReturn(12345L);
IdMapper mapper = mapper(encoder, Radix.STRING, monitor);
PropertyValueLookup ids = values("10", "9");
for (int i = 0; i < 2; i++) {
mapper.put(ids.lookupProperty(i, NULL), i, Group.GLOBAL);
}
// WHEN
ProgressListener progress = mock(ProgressListener.class);
Collector collector = mock(Collector.class);
mapper.prepare(ids, collector, progress);
// THEN
verifyNoMoreInteractions(collector);
verify(monitor).numberOfCollisions(2);
assertEquals(0L, mapper.get("10", Group.GLOBAL));
assertEquals(1L, mapper.get("9", Group.GLOBAL));
// 7 times since SPLIT+SORT+DETECT+RESOLVE+SPLIT+SORT,DEDUPLICATE
verify(progress, times(7)).started(anyString());
verify(progress, times(7)).done();
}
use of org.neo4j.internal.batchimport.input.Collector in project neo4j by neo4j.
the class EncodingIdMapperTest method shouldCopeWithMixedActualAndAccidentalCollisions.
@Test
public void shouldCopeWithMixedActualAndAccidentalCollisions() {
// GIVEN
EncodingIdMapper.Monitor monitor = mock(EncodingIdMapper.Monitor.class);
Encoder encoder = mock(Encoder.class);
// Create these explicit instances so that we can use them in mock, even for same values
String a = "a";
String b = "b";
String c = "c";
String a2 = "a";
String e = "e";
String f = "f";
when(encoder.encode(a)).thenReturn(1L);
when(encoder.encode(b)).thenReturn(1L);
when(encoder.encode(c)).thenReturn(3L);
when(encoder.encode(a2)).thenReturn(1L);
when(encoder.encode(e)).thenReturn(2L);
when(encoder.encode(f)).thenReturn(1L);
Group groupA = groups.getOrCreate("A");
Group groupB = groups.getOrCreate("B");
IdMapper mapper = mapper(encoder, Radix.STRING, monitor);
PropertyValueLookup ids = values("a", "b", "c", "a", "e", "f");
Group[] groups = new Group[] { groupA, groupA, groupA, groupB, groupB, groupB };
// WHEN
for (int i = 0; i < 6; i++) {
mapper.put(ids.lookupProperty(i, NULL), i, groups[i]);
}
Collector collector = mock(Collector.class);
mapper.prepare(ids, collector, mock(ProgressListener.class));
// THEN
verify(monitor).numberOfCollisions(4);
assertEquals(0L, mapper.get(a, groupA));
assertEquals(1L, mapper.get(b, groupA));
assertEquals(2L, mapper.get(c, groupA));
assertEquals(3L, mapper.get(a2, groupB));
assertEquals(4L, mapper.get(e, groupB));
assertEquals(5L, mapper.get(f, groupB));
}
use of org.neo4j.internal.batchimport.input.Collector in project neo4j by neo4j.
the class EncodingIdMapperTest method tracePageCacheAccessOnCollisions.
@Test
public void tracePageCacheAccessOnCollisions() {
EncodingIdMapper.Monitor monitor = mock(EncodingIdMapper.Monitor.class);
Encoder encoder = mock(Encoder.class);
when(encoder.encode(any())).thenReturn(12345L);
var pageCacheTracer = new DefaultPageCacheTracer();
IdMapper mapper = mapper(encoder, Radix.STRING, monitor, pageCacheTracer);
PropertyValueLookup ids = (nodeId, cursorContext) -> {
cursorContext.getCursorTracer().beginPin(false, 1, null).done();
return nodeId + "";
};
int expectedCollisions = 2;
for (int i = 0; i < expectedCollisions; i++) {
mapper.put(ids.lookupProperty(i, NULL), i, Group.GLOBAL);
}
ProgressListener progress = mock(ProgressListener.class);
Collector collector = mock(Collector.class);
mapper.prepare(ids, collector, progress);
verifyNoMoreInteractions(collector);
verify(monitor).numberOfCollisions(expectedCollisions);
assertEquals(expectedCollisions, pageCacheTracer.pins());
assertEquals(expectedCollisions, pageCacheTracer.unpins());
}
Aggregations