use of org.neo4j.kernel.lifecycle.Lifespan in project neo4j by neo4j.
the class AbstractKeyValueStoreTest method shouldNotPickCorruptStoreFile.
@Test
public void shouldNotPickCorruptStoreFile() throws Exception {
// given
Store store = createTestStore();
RotationStrategy rotation = store.rotationStrategy;
// when
File[] files = new File[10];
{
Pair<File, KeyValueStoreFile> file = rotation.create(EMPTY_DATA_PROVIDER, 1);
files[0] = file.first();
for (int txId = 2, i = 1; i < files.length; txId <<= 1, i++) {
KeyValueStoreFile old = file.other();
final int data = txId;
file = rotation.next(file.first(), Headers.headersBuilder().put(TX_ID, (long) txId).headers(), data(new Entry() {
@Override
public void write(WritableBuffer key, WritableBuffer value) {
key.putByte(0, (byte) 'f');
key.putByte(1, (byte) 'o');
key.putByte(2, (byte) 'o');
value.putInt(0, data);
}
}));
old.close();
files[i] = file.first();
}
file.other().close();
}
// Corrupt the last files
try (StoreChannel channel = resourceManager.fileSystem().open(files[9], "rw")) {
// ruin the header
channel.position(16);
ByteBuffer value = ByteBuffer.allocate(16);
value.put((byte) 0);
value.flip();
channel.writeAll(value);
}
try (StoreChannel channel = resourceManager.fileSystem().open(files[8], "rw")) {
// ruin the header
channel.position(32);
ByteBuffer value = ByteBuffer.allocate(16);
value.put((byte) 17);
value.flip();
channel.writeAll(value);
}
try (StoreChannel channel = resourceManager.fileSystem().open(files[7], "rw")) {
// ruin the header
channel.position(32 + 32 + 32 + 16);
ByteBuffer value = ByteBuffer.allocate(16);
value.putLong(0);
value.putLong(0);
value.flip();
channel.writeAll(value);
}
// then
try (Lifespan life = new Lifespan()) {
life.add(store);
assertEquals(64L, store.headers().get(TX_ID).longValue());
}
}
use of org.neo4j.kernel.lifecycle.Lifespan in project neo4j by neo4j.
the class CountsComputerTest method rebuildCounts.
private void rebuildCounts(long lastCommittedTransactionId) throws IOException {
cleanupCountsForRebuilding();
StoreFactory storeFactory = new StoreFactory(dir, pageCache, fs, NullLogProvider.getInstance());
try (Lifespan life = new Lifespan();
NeoStores neoStores = storeFactory.openAllNeoStores()) {
NodeStore nodeStore = neoStores.getNodeStore();
RelationshipStore relationshipStore = neoStores.getRelationshipStore();
int highLabelId = (int) neoStores.getLabelTokenStore().getHighId();
int highRelationshipTypeId = (int) neoStores.getRelationshipTypeTokenStore().getHighId();
CountsComputer countsComputer = new CountsComputer(lastCommittedTransactionId, nodeStore, relationshipStore, highLabelId, highRelationshipTypeId);
CountsTracker countsTracker = createCountsTracker();
life.add(countsTracker.setInitializer(countsComputer));
}
}
Aggregations