@Override public ResourceIterator<File> snapshotFiles() { return delegate.snapshotFiles(); }
@Override public ResourceIterator<File> snapshotFiles() { return accessor.snapshotFiles(); }
@Override public ResourceIterator<File> snapshotFiles() { return accessor.snapshotFiles(); }
@Override public ResourceIterator<File> snapshotFiles() { return actual.snapshotFiles(); }
@Test public void shouldSnapshotOnlineIndexes() throws Exception { // GIVEN int indexId = 1; int indexId2 = 2; StoreIndexDescriptor rule1 = storeIndex( indexId, 2, 3, PROVIDER_DESCRIPTOR ); StoreIndexDescriptor rule2 = storeIndex( indexId2, 4, 5, PROVIDER_DESCRIPTOR ); IndexAccessor indexAccessor = mock( IndexAccessor.class ); IndexingService indexing = newIndexingServiceWithMockedDependencies( mock( IndexPopulator.class ), indexAccessor, new DataUpdates( ), rule1, rule2 ); File theFile = new File( "Blah" ); when( indexAccessor.snapshotFiles()).thenAnswer( newResourceIterator( theFile ) ); when( indexProvider.getInitialState( rule1 ) ).thenReturn( ONLINE ); when( indexProvider.getInitialState( rule2 ) ).thenReturn( ONLINE ); when( storeView.indexSample( anyLong(), any( DoubleLongRegister.class ) ) ) .thenReturn( newDoubleLongRegister( 32L, 32L ) ); life.start(); // WHEN ResourceIterator<File> files = indexing.snapshotIndexFiles(); // THEN // We get a snapshot per online index assertThat( asCollection( files ), equalTo( asCollection( iterator( theFile, theFile ) ) ) ); }
@Test public void shouldNotSnapshotPopulatingIndexes() throws Exception { // GIVEN CountDownLatch populatorLatch = new CountDownLatch( 1 ); IndexAccessor indexAccessor = mock(IndexAccessor.class); int indexId = 1; int indexId2 = 2; StoreIndexDescriptor rule1 = storeIndex( indexId, 2, 3, PROVIDER_DESCRIPTOR ); StoreIndexDescriptor rule2 = storeIndex( indexId2, 4, 5, PROVIDER_DESCRIPTOR ); IndexingService indexing = newIndexingServiceWithMockedDependencies( populator, indexAccessor, new DataUpdates(), rule1, rule2 ); File theFile = new File( "Blah" ); doAnswer( waitForLatch( populatorLatch ) ).when( populator ).create(); when( indexAccessor.snapshotFiles() ).thenAnswer( newResourceIterator( theFile ) ); when( indexProvider.getInitialState( rule1 ) ).thenReturn( POPULATING ); when( indexProvider.getInitialState( rule2 ) ).thenReturn( ONLINE ); when( storeView.indexSample( anyLong(), any( DoubleLongRegister.class ) ) ).thenReturn( newDoubleLongRegister( 32L, 32L ) ); life.start(); // WHEN ResourceIterator<File> files = indexing.snapshotIndexFiles(); populatorLatch.countDown(); // only now, after the snapshot, is the population job allowed to finish waitForIndexesToComeOnline( indexing, indexId, indexId2 ); // THEN // We get a snapshot from the online index, but no snapshot from the populating one assertThat( asCollection( files ), equalTo( asCollection( iterator( theFile ) ) ) ); }
@Override public ResourceIterator<File> snapshotFiles() { return delegate.snapshotFiles(); }
@Override public ResourceIterator<File> snapshotFiles() { return accessor.snapshotFiles(); }