use of java.util.concurrent.atomic.AtomicLong in project neo4j by neo4j.
the class EncodeGroupsStepTest method shouldEncodeGroupChains.
@SuppressWarnings("unchecked")
@Test
public void shouldEncodeGroupChains() throws Throwable {
// GIVEN
StageControl control = mock(StageControl.class);
final AtomicLong nextId = new AtomicLong();
RecordStore<RelationshipGroupRecord> store = mock(RecordStore.class);
when(store.nextId()).thenAnswer(invocation -> nextId.incrementAndGet());
doAnswer(invocation -> {
invocation.getArgumentAt(0, RelationshipGroupRecord.class).setFirstOut(1);
return null;
}).when(store).prepareForCommit(any(RelationshipGroupRecord.class));
Configuration config = Configuration.withBatchSize(DEFAULT, 10);
EncodeGroupsStep encoder = new EncodeGroupsStep(control, config, store);
// WHEN
encoder.start(Step.ORDER_SEND_DOWNSTREAM);
Catcher catcher = new Catcher();
encoder.process(batch(new Group(1, 3), new Group(2, 3), new Group(3, 4)), catcher);
encoder.process(batch(new Group(4, 2), new Group(5, 10)), catcher);
encoder.process(batch(new Group(6, 35)), catcher);
encoder.process(batch(new Group(7, 2)), catcher);
encoder.endOfUpstream();
while (!encoder.isCompleted()) {
Thread.sleep(10);
}
encoder.close();
// THEN
assertEquals(4, catcher.batches.size());
long lastOwningNodeLastBatch = -1;
for (RelationshipGroupRecord[] batch : catcher.batches) {
assertBatch(batch, lastOwningNodeLastBatch);
lastOwningNodeLastBatch = batch[batch.length - 1].getOwningNode();
}
}
use of java.util.concurrent.atomic.AtomicLong in project neo4j by neo4j.
the class CsvInputBatchImportIT method buildUpExpectedData.
private void buildUpExpectedData(List<InputNode> nodeData, List<InputRelationship> relationshipData, Map<String, InputNode> expectedNodes, Map<String, String[]> expectedNodeNames, Map<String, Map<String, Map<String, AtomicInteger>>> expectedRelationships, Map<String, AtomicLong> nodeCounts, Map<String, Map<String, Map<String, AtomicLong>>> relationshipCounts) {
for (InputNode node : nodeData) {
expectedNodes.put((String) node.id(), node);
expectedNodeNames.put(nameOf(node), node.labels());
countNodeLabels(nodeCounts, node.labels());
}
for (InputRelationship relationship : relationshipData) {
// Expected relationship counts per node, type and direction
InputNode startNode = expectedNodes.get(relationship.startNode());
InputNode endNode = expectedNodes.get(relationship.endNode());
{
expectedRelationships.get(nameOf(startNode)).get(nameOf(endNode)).get(relationship.type()).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.type()).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.type());
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.type()).get(endNodeLabelName).incrementAndGet();
}
}
}
use of java.util.concurrent.atomic.AtomicLong in project neo4j by neo4j.
the class DelayedRenewableTimeoutServiceTest method shouldTimeOutAfterTimeoutPeriod.
@Test
public void shouldTimeOutAfterTimeoutPeriod() throws Throwable {
// given
final AtomicLong timeoutCount = new AtomicLong();
DelayedRenewableTimeoutService timeoutService = new DelayedRenewableTimeoutService(Clocks.systemClock(), getInstance());
long startTime = System.currentTimeMillis();
timeoutService.create(Timeouts.FOOBAR, TIMEOUT_MS, 0, timeout -> timeoutCount.incrementAndGet());
life.add(timeoutService);
Predicates.await(timeoutCount::get, count -> count == 1, LONG_TIME_MS, MILLISECONDS, 1, MILLISECONDS);
long runTime = System.currentTimeMillis() - startTime;
assertThat(runTime, greaterThanOrEqualTo(TIMEOUT_MS - ERROR_MS));
}
use of java.util.concurrent.atomic.AtomicLong in project neo4j by neo4j.
the class CrashGenerationCleaner method clean.
// === Methods about the execution and threading ===
public void clean() throws IOException {
assert unstableGeneration > stableGeneration;
assert unstableGeneration - stableGeneration > 1;
long startTime = currentTimeMillis();
int threads = availableProcessors;
ExecutorService executor = Executors.newFixedThreadPool(threads);
AtomicLong nextId = new AtomicLong(lowTreeNodeId);
AtomicReference<Throwable> error = new AtomicReference<>();
AtomicInteger cleanedPointers = new AtomicInteger();
for (int i = 0; i < threads; i++) {
executor.submit(cleaner(nextId, error, cleanedPointers));
}
executor.shutdown();
try {
long lastProgression = nextId.get();
// I/O congestion spikes w/o failing in vain.
while (!executor.awaitTermination(30, SECONDS)) {
if (lastProgression == nextId.get()) {
// No progression at all, abort?
error.compareAndSet(null, new IOException("No progress, so forcing abort"));
}
lastProgression = nextId.get();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
Throwable finalError = error.get();
if (finalError != null) {
throw launderedException(IOException.class, finalError);
}
long endTime = currentTimeMillis();
monitor.recoveryCompleted(highTreeNodeId - lowTreeNodeId, cleanedPointers.get(), endTime - startTime);
}
use of java.util.concurrent.atomic.AtomicLong in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldDeleteDynamicLabelsForDeletedNode.
@Test
public void shouldDeleteDynamicLabelsForDeletedNode() throws Throwable {
// GIVEN a store that has got a node with a dynamic label record
NeoStores store = neoStoresRule.open();
BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(store, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
AtomicLong nodeId = new AtomicLong();
AtomicLong dynamicLabelRecordId = new AtomicLong();
apply(applier, transaction(nodeWithDynamicLabelRecord(store, nodeId, dynamicLabelRecordId)));
assertDynamicLabelRecordInUse(store, dynamicLabelRecordId.get(), true);
// WHEN applying a transaction where the node is deleted
apply(applier, transaction(deleteNode(store, nodeId.get())));
// THEN the dynamic label record should also be deleted
assertDynamicLabelRecordInUse(store, dynamicLabelRecordId.get(), false);
}
Aggregations