private CountsTracker newTracker( SystemNanoClock clock, VersionContextSupplier versionContextSupplier ) { return new CountsTracker( resourceManager.logProvider(), resourceManager.fileSystem(), resourceManager.pageCache(), Config.defaults(), resourceManager.testDirectory().databaseLayout(), clock, versionContextSupplier ) .setInitializer( new DataInitializer<CountsAccessor.Updater>() { @Override public void initialize( CountsAccessor.Updater updater ) { } @Override public long initialVersion() { return FileVersion.INITIAL_TX_ID; } } ); }
private Statement lifeStatement( Statement base, Description description ) { Life initialLifecycle = description.getAnnotation( Life.class ); if ( initialLifecycle != null ) { base = initialise( base, initialLifecycle.value() ); } return life.apply( base, description ); }
@Test public void shouldBeAbleToStartAndStopTheStore() { // given resourceManager.managed( newTracker() ); // when resourceManager.lifeStarts(); resourceManager.lifeShutsDown(); }
private Store( long rotationTimeout, HeaderField<?>... headerFields ) { super( resourceManager.fileSystem(), resourceManager.pageCache(), resourceManager.testDirectory().databaseLayout(), null, null, new RotationTimerFactory( Clocks.nanoClock(), rotationTimeout ), EmptyVersionContextSupplier.EMPTY, 16, 16, headerFields ); this.headerFields = headerFields; setEntryUpdaterInitializer( new DataInitializer<EntryUpdater<String>>() { @Override public void initialize( EntryUpdater<String> stringEntryUpdater ) { } @Override public long initialVersion() { return 0; } } ); }
@Test @Resources.Life( STARTED ) @SuppressWarnings( "unchecked" ) public void retryLookupOnConcurrentStoreStateChange() throws IOException { Store store = resourceManager.managed( new Store() ); ProgressiveState<String> workingState = stateWithLookup( () -> true ); ProgressiveState<String> staleState = stateWithLookup( () -> { setState( store, workingState ); throw new FileIsNotMappedException( new File( "/files/was/rotated/concurrently/during/lookup" ) ); } ); setState( store, staleState ); assertEquals( "New state contains stored value", "value", store.lookup( "test", stringReader( "value" ) ) ); // Should have 2 invocations: first throws exception, second re-read value. verify( staleState, times( 1 ) ).lookup( any(), any() ); verify( workingState, times( 1 ) ).lookup( any(), any() ); }
public PageCache pageCache() { return pageCacheRule.getPageCache( fileSystem() ); }
@Override public Statement apply( Statement base, Description description ) { return fs.apply( testDirectory.apply( pageCacheRule.apply( lifeStatement( base, description ), description ), description ), description ); }
@Test @Resources.Life( STARTED ) public void shouldRotateStore() throws Exception { // given Store store = resourceManager.managed( new Store() ); // when store.prepareRotation( 0 ).rotate(); }
try ( StoreChannel channel = resourceManager.fileSystem().open( files[9], OpenMode.READ_WRITE ) ) channel.writeAll( value ); try ( StoreChannel channel = resourceManager.fileSystem().open( files[8], OpenMode.READ_WRITE ) ) channel.writeAll( value ); try ( StoreChannel channel = resourceManager.fileSystem().open( files[7], OpenMode.READ_WRITE ) )
resourceManager.logProvider(), resourceManager.fileSystem(), resourceManager.pageCache(), Config.defaults(), resourceManager.testDirectory().databaseLayout(), EmptyVersionContextSupplier.EMPTY )
@Test public void shouldStartAndStopStore() { // given resourceManager.managed( new Store() ); // when resourceManager.lifeStarts(); resourceManager.lifeShutsDown(); }
@Test @Resources.Life( STARTED ) public void postStateUpdatesCountedOnlyForTransactionsGreaterThanRotationVersion() throws IOException, InterruptedException, ExecutionException { final Store store = resourceManager.managed( createTestStore() ); PreparedRotation rotation = store.prepareRotation( 2 ); updateStore( store, 4 ); updateStore( store, 3 ); updateStore( store, 1 ); updateStore( store, 2 ); assertEquals( 2, rotation.rotate() ); Future<Long> rotationFuture = threading.executeAndAwait( store.rotation, 5L, thread -> Thread.State.TIMED_WAITING == thread.getState(), 100, SECONDS ); Thread.sleep( TimeUnit.SECONDS.toMillis( 1 ) ); assertFalse( rotationFuture.isDone() ); updateStore( store, 5 ); assertEquals( 5, rotationFuture.get().longValue() ); }
nextNext.other().close(); try ( StoreChannel channel = resourceManager.fileSystem().open( corrupted, OpenMode.READ_WRITE ) )
@Test @Resources.Life( STARTED ) public void shouldFailRotationAfterTimeout() throws IOException { // GIVEN final Store store = resourceManager.managed( createTestStore( 0 ) ); // THEN expectedException.expect( RotationTimeoutException.class ); // WHEN store.prepareRotation( 10L ).rotate(); }
final Store store = resourceManager.managed( createTestStore() );
@Test @Resources.Life( STARTED ) public void shouldNotRotateIfNoDataChanges() throws Exception { // given CountsTracker tracker = resourceManager.managed( newTracker() ); File before = tracker.currentFile(); // when tracker.rotate( tracker.txId() ); // then assertSame( "not rotated", before, tracker.currentFile() ); }
final CountsTracker tracker = resourceManager.managed( newTracker() ); try ( CountsAccessor.Updater tx = tracker.apply( 2 ).get() )
@Test @Resources.Life( STARTED ) public void shouldRotateWithCorrectVersion() throws Exception { // given final Store store = resourceManager.managed( createTestStore() ); updateStore( store, 1 ); PreparedRotation rotation = store.prepareRotation( 2 ); updateStore( store, 2 ); rotation.rotate(); // then assertEquals( 2, store.headers().get( TX_ID ).longValue() ); store.prepareRotation( 2 ).rotate(); }
@Test @Resources.Life( STARTED ) public void shouldRotateOnDataChangesEvenIfTransactionIsUnchanged() throws Exception { // given CountsTracker tracker = resourceManager.managed( newTracker() ); File before = tracker.currentFile(); try ( CountsAccessor.IndexStatsUpdater updater = tracker.updateIndexCounts() ) { updater.incrementIndexUpdates( 7, 100 ); } // when tracker.rotate( tracker.txId() ); // then assertNotEquals( "rotated", before, tracker.currentFile() ); }
@Test @Resources.Life( STARTED ) public void accessClosedStateShouldThrow() throws Exception { Store store = resourceManager.managed( new Store() ); store.put( "test", "value" ); store.prepareRotation( 0 ).rotate(); ProgressiveState<String> lookupState = store.state; store.prepareRotation( 0 ).rotate(); expectedException.expect( FileIsNotMappedException.class ); expectedException.expectMessage( "File has been unmapped" ); lookupState.lookup( "test", new ValueSink() { @Override protected void value( ReadableBuffer value ) { // empty } } ); }