/** Closed the {@link IdGenerator} used by this store */ void closeIdGenerator() { if ( idGenerator != null ) { idGenerator.close(); } }
@Override public void close() { delegate.close(); }
private void closeIdGenerator( IdGenerator idGenerator ) { idGenerator.close(); }
@Test public void shouldCloseStoreFileFirstAndIdGeneratorAfter() throws Throwable { // given TheStore store = newStore(); InOrder inOrder = inOrder( pageFile, idGenerator ); // when store.close(); // then inOrder.verify( pageFile, times( 1 ) ).close(); inOrder.verify( idGenerator, times( 1 ) ).close(); }
private void closeStoreFile() throws IOException { try { /* * Note: the closing ordering here is important! * It is the case since we wand to mark the id generator as closed cleanly ONLY IF * also the store file is cleanly shutdown. */ if ( pagedFile != null ) { pagedFile.close(); } if ( idGenerator != null ) { if ( contains( openOptions, DELETE_ON_CLOSE ) ) { idGenerator.delete(); } else { idGenerator.close(); } } } finally { pagedFile = null; } }
@Test void createCommunityBufferedContextByDefault() { IdContextFactory idContextFactory = IdContextFactoryBuilder.of( fs, jobScheduler ).build(); DatabaseIdContext idContext = idContextFactory.createIdContext( "database" ); IdGeneratorFactory idGeneratorFactory = idContext.getIdGeneratorFactory(); assertThat( idContext.getIdController(), instanceOf( BufferedIdController.class ) ); assertThat( idGeneratorFactory, instanceOf( BufferingIdGeneratorFactory.class ) ); ((BufferingIdGeneratorFactory)idGeneratorFactory).initialize( () -> mock( KernelTransactionsSnapshot.class ) ); idGeneratorFactory.open( testDirectory.file( "a"), IdType.NODE, () -> 0, 100 ).close(); idGeneratorFactory.open( testDirectory.file( "b"), IdType.PROPERTY, () -> 0, 100 ).close(); BufferingIdGeneratorFactory bufferedFactory = (BufferingIdGeneratorFactory) idGeneratorFactory; assertThat( bufferedFactory.get( IdType.NODE ), instanceOf( IdGeneratorImpl.class ) ); assertThat( bufferedFactory.get( IdType.PROPERTY ), not( instanceOf( IdGeneratorImpl.class ) ) ); }
@Test public void constructorShouldNotCallHighIdSupplierOnCleanIdFile() { // Given // A non empty, clean id file IdContainer.createEmptyIdFile( fsr.get(), file, 42, true ); // and a mock supplier to test against LongSupplier highId = mock( LongSupplier.class ); // When // An IdGenerator is created over the previous properly closed file IdGenerator idGenerator = new IdGeneratorImpl( fsr.get(), file, 100, 100, false, IdType.NODE, highId ); idGenerator.close(); // Then // The supplier must have remained untouched verifyZeroInteractions( highId ); } }
@Test public void mustOverwriteExistingFileIfRequested() { IdGeneratorImpl.createGenerator( fs, idGeneratorFile(), 0, false ); IdGenerator idGenerator = new IdGeneratorImpl( fs, idGeneratorFile(), 1008, 1000, false, IdType.NODE, () -> 0L ); long[] firstFirstIds = new long[]{idGenerator.nextId(), idGenerator.nextId(), idGenerator.nextId()}; idGenerator.close(); IdGeneratorImpl.createGenerator( fs, idGeneratorFile(), 0, false ); idGenerator = new IdGeneratorImpl( fs, idGeneratorFile(), 1008, 1000, false, IdType.NODE, () -> 0L ); long[] secondFirstIds = new long[]{idGenerator.nextId(), idGenerator.nextId(), idGenerator.nextId()}; idGenerator.close(); // Basically, recreating the id file should be the same as start over with the ids. assertThat( secondFirstIds, is( firstFirstIds ) ); }
@Test public void correctDefragCountWhenHaveIdsInFile() { IdGeneratorImpl.createGenerator( fsr.get(), file, 100, false ); IdGenerator idGenerator = new IdGeneratorImpl( fsr.get(), file, 100, 100, true, IdType.NODE, () -> 100L ); idGenerator.freeId( 5 ); idGenerator.close(); IdGenerator reloadedIdGenerator = new IdGeneratorImpl( fsr.get(), file, 100, 100, true, IdType.NODE, () -> 100L ); assertEquals( 1, reloadedIdGenerator.getDefragCount() ); assertEquals( 5, reloadedIdGenerator.nextId() ); assertEquals( 0, reloadedIdGenerator.getDefragCount() ); }
/** Closed the {@link IdGenerator} used by this store */ void closeIdGenerator() { if ( idGenerator != null ) { idGenerator.close(); } }
@Override public void close() { delegate.close(); }
@Override public void close() { delegate.close(); }
void switchToRaft() { long highId = delegate.getHighId(); delegate.close(); delegate = new ReplicatedIdGenerator( idType, highId, acquirer, logProvider ); }
private long getHighId( File coreDir, DefaultIdGeneratorFactory factory, IdType idType, String store ) { IdGenerator idGenerator = factory.open( new File( coreDir, idFile( store ) ), idType, -1, Long.MAX_VALUE ); long highId = idGenerator.getHighId(); idGenerator.close(); return highId; }
private long getHighId( File coreDir, DefaultIdGeneratorFactory factory, IdType idType, String store ) { IdGenerator idGenerator = factory.open( new File( coreDir, idFile( store ) ), idType, () -> -1L, Long.MAX_VALUE ); long highId = idGenerator.getHighId(); idGenerator.close(); return highId; }
private void closeStoreFile() throws IOException { try { /* * Note: the closing ordering here is important! * It is the case since we wand to mark the id generator as closed cleanly ONLY IF * also the store file is cleanly shutdown. */ if ( pagedFile != null ) { pagedFile.close(); } if ( idGenerator != null ) { if ( contains( openOptions, DELETE_ON_CLOSE ) ) { idGenerator.delete(); } else { idGenerator.close(); } } } finally { pagedFile = null; } }