Refine search
@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 shouldBeAbleToReadWrittenGenerator() { // Given IdGeneratorImpl.createGenerator( fsr.get(), file, 42, false ); IdGeneratorImpl idGenerator = new IdGeneratorImpl( fsr.get(), file, 100, 100, false, IdType.NODE, () -> 42L ); idGenerator.close(); // When idGenerator = new IdGeneratorImpl( fsr.get(), file, 100, 100, false, IdType.NODE, () -> 0L ); // Then assertThat( idGenerator.getHighId(), equalTo( 42L ) ); }
@Test public void shouldNotAcceptMinusOne() { // GIVEN IdGeneratorImpl.createGenerator( fsr.get(), file, 0, false ); IdGenerator idGenerator = new IdGeneratorImpl( fsr.get(), file, 100, 100, false, IdType.NODE, () -> 0L ); expectedException.expect( NegativeIdException.class ); // WHEN idGenerator.setHighId( -1 ); }
@Test public void flushOfThePageCacheHappensOnlyOnceDuringShutdown() throws Throwable { PageCache pageCache = spy( pageCacheRule.getPageCache( fs.get() ) ); NeoStoreDataSource ds = dsRule.getDataSource( dir.databaseLayout(), fs.get(), pageCache ); ds.start(); verify( pageCache, never() ).flushAndForce(); verify( pageCache, never() ).flushAndForce( any( IOLimiter.class ) ); ds.stop(); ds.shutdown(); verify( pageCache ).flushAndForce( IOLimiter.UNLIMITED ); }
@Test public void throwsWhenGivenHighIdIsTooHigh() { long maxId = 10; IdGeneratorImpl.createGenerator( fsr.get(), file, 0, false ); IdGenerator idGenerator = new IdGeneratorImpl( fsr.get(), file, 1, maxId, false, IdType.RELATIONSHIP_TYPE_TOKEN, () -> 0L ); expectedException.expect( IdCapacityExceededException.class ); expectedException.expectMessage( "Maximum id limit for RELATIONSHIP_TYPE_TOKEN has been reached. Generated id 11 is out of permitted range [0, 10]." ); idGenerator.setHighId( maxId + 1 ); }
/** * It should be fine to set high id to {@link IdGeneratorImpl#INTEGER_MINUS_ONE}. * It will just be never returned from {@link IdGeneratorImpl#nextId()}. */ @Test public void highIdCouldBeSetToReservedId() { IdGeneratorImpl.createGenerator( fsr.get(), file, 0, false ); IdGenerator idGenerator = new IdGeneratorImpl( fsr.get(), file, 1, Long.MAX_VALUE, false, IdType.NODE, () -> 0L ); idGenerator.setHighId( IdGeneratorImpl.INTEGER_MINUS_ONE ); assertEquals( IdGeneratorImpl.INTEGER_MINUS_ONE + 1, idGenerator.nextId() ); }
@Test public void constructorShouldCallHighIdSupplierOnNonExistingIdFile() { // Given // An empty file (default, nothing to do) // and a mock supplier to test against LongSupplier highId = mock( LongSupplier.class ); when( highId.getAsLong() ).thenReturn( 0L ); // necessary, otherwise it runs into NPE in the constructor below // When // The id generator is started IdGeneratorImpl idGenerator = new IdGeneratorImpl( fsr.get(), file, 100, 100, false, IdType.NODE, highId ); // Then // The highId supplier must have been called to get the high id verify( highId ).getAsLong(); idGenerator.close(); }
@Test public void flushOfThePageCacheOnShutdownHappensIfTheDbIsHealthy() throws Throwable { PageCache pageCache = spy( pageCacheRule.getPageCache( fs.get() ) ); NeoStoreDataSource ds = dsRule.getDataSource( dir.databaseLayout(), fs.get(), pageCache ); ds.start(); verify( pageCache, never() ).flushAndForce(); ds.stop(); ds.shutdown(); verify( pageCache ).flushAndForce( IOLimiter.UNLIMITED ); }
@Test public void flushOfThePageCacheOnShutdownDoesNotHappenIfTheDbIsUnhealthy() throws Throwable { DatabaseHealth health = mock( DatabaseHealth.class ); when( health.isHealthy() ).thenReturn( false ); PageCache pageCache = spy( pageCacheRule.getPageCache( fs.get() ) ); Dependencies dependencies = new Dependencies(); dependencies.satisfyDependency( health ); NeoStoreDataSource ds = dsRule.getDataSource( dir.databaseLayout(), fs.get(), pageCache, dependencies ); ds.start(); verify( pageCache, never() ).flushAndForce(); ds.stop(); ds.shutdown(); verify( pageCache, never() ).flushAndForce( IOLimiter.UNLIMITED ); }
@Test public void throwsWhenNextIdIsTooHigh() { long maxId = 10; IdGeneratorImpl.createGenerator( fsr.get(), file, 0, false ); IdGenerator idGenerator = new IdGeneratorImpl( fsr.get(), file, 1, maxId, false, IdType.NODE, () -> 0L ); for ( long i = 0; i <= maxId; i++ ) { idGenerator.nextId(); } expectedException.expect( IdCapacityExceededException.class ); expectedException.expectMessage( "Maximum id limit for NODE has been reached. Generated id 11 is out of " + "permitted range [0, 10]." ); idGenerator.nextId(); }
@Test public void shouldNotReturnIdsPersistedDuringThisRunIfAggressiveIsFalse() throws Exception { // given StoreChannel channel = spy( fs.get().open( new File( "id.file" ), OpenMode.READ_WRITE ) ); int batchSize = 10; FreeIdKeeper keeper = getFreeIdKeeper( channel, batchSize ); // when // enough ids are persisted to overflow for ( int i = 0; i < batchSize; i++ ) { keeper.freeId( i ); } // then // stuff must have been written to disk verify( channel, times( 1 ) ).write( any( ByteBuffer.class ) ); // and no ids can be returned assertEquals( NO_RESULT, keeper.getId() ); }
@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() ); }
@Test public void shouldFitAsManyPagesAsItCan() { // Given long pageCount = 60; long memory = MuninnPageCache.memoryRequiredForPages( pageCount ); Config config = Config.defaults( pagecache_memory, Long.toString( memory ) ); // When ConfiguringPageCacheFactory factory = new ConfiguringPageCacheFactory( fsRule.get(), config, PageCacheTracer.NULL, PageCursorTracerSupplier.NULL, NullLog.getInstance(), EmptyVersionContextSupplier.EMPTY, jobScheduler ); // Then try ( PageCache cache = factory.getOrCreatePageCache() ) { assertThat( cache.pageSize(), equalTo( PageCache.PAGE_SIZE ) ); assertThat( cache.maxCachedPages(), equalTo( pageCount ) ); } }
@Test( expected = ToolFailureException.class ) public void failOnNotCleanlyShutdownStoreWithLogsInCustomAbsoluteLocation() throws Exception { File customConfigFile = testDirectory.file( "customConfig" ); File otherLocation = testDirectory.directory( "otherLocation" ); Config customConfig = Config.defaults( logical_logs_location, otherLocation.getAbsolutePath() ); createGraphDbAndKillIt( customConfig ); MapUtil.store( customConfig.getRaw(), customConfigFile ); String[] args = {testDirectory.databaseDir().getPath(), "-config", customConfigFile.getPath()}; runConsistencyCheckToolWith( fs.get(), args ); }
@Test public void notAllowCreateDynamicStoreWithNegativeBlockSize() { Config config = Config.defaults(); StoreFactory sf = getStoreFactory( config, databaseLayout, fs.get(), NullLogProvider.getInstance() ); exception.expect( IllegalArgumentException.class ); exception.expectMessage( "Block size of dynamic array store should be positive integer." ); try ( NeoStores neoStores = sf.openNeoStores( true ) ) { neoStores.createDynamicArrayStore( new File( "someStore" ), new File( "someIdFile" ), IdType.ARRAY_BLOCK, -2 ); } }
@Test public void writingOfHeaderRecordDuringInitialiseNewStoreFileMustThrowOnPageOverflow() throws Exception { // 16-byte header will overflow an 8-byte page size PageCacheRule.PageCacheConfig pageCacheConfig = PageCacheRule.config(); PageCache pageCache = pageCacheRule.getPageCache( fs.get(), pageCacheConfig, config ); MyStore store = new MyStore( config, pageCache, PAGE_SIZE + 1 ); assertThrowsUnderlyingStorageException( () -> store.initialise( true ) ); }
@Test public void extractHeaderRecordDuringLoadStorageMustThrowOnPageOverflow() throws Exception { MyStore first = new MyStore( config, pageCacheRule.getPageCache( fs.get(), config ), 8 ); first.initialise( true ); first.close(); PageCacheRule.PageCacheConfig pageCacheConfig = PageCacheRule.config(); PageCache pageCache = pageCacheRule.getPageCache( fs.get(), pageCacheConfig, config ); MyStore second = new MyStore( config, pageCache, PAGE_SIZE + 1 ); assertThrowsUnderlyingStorageException( () -> second.initialise( false ) ); }
@Test( expected = ToolFailureException.class ) public void failOnNotCleanlyShutdownStoreWithLogsInCustomRelativeLocation() throws Exception { File customConfigFile = testDirectory.file( "customConfig" ); Config customConfig = Config.defaults( logical_logs_location, "otherLocation" ); createGraphDbAndKillIt( customConfig ); MapUtil.store( customConfig.getRaw(), fs.openAsOutputStream( customConfigFile, false ) ); String[] args = {testDirectory.databaseDir().getPath(), "-config", customConfigFile.getPath()}; runConsistencyCheckToolWith( fs.get(), args ); }