}
public void testIncrementalIndexUpdateNoUpdateNecessary()
throws Exception
{
Mockery mockery = new Mockery();
final String indexUrl = repositoryUrl + ".index";
final Date contextTimestamp = df.parse( "20081128000000.000 -0600" );
final ResourceFetcher mockFetcher = mockery.mock( ResourceFetcher.class );
final IndexingContext tempContext = mockery.mock( IndexingContext.class );
final Properties localProps = new Properties();
localProps.setProperty( IndexingContext.INDEX_CHUNK_COUNTER, "3" );
localProps.setProperty( IndexingContext.INDEX_CHAIN_ID, "someid" );
mockery.checking( new Expectations()
{
{
allowing( tempContext ).getTimestamp();
will( returnValue( contextTimestamp ) );
allowing( tempContext ).getId();
will( returnValue( repositoryId ) );
allowing( tempContext ).getIndexUpdateUrl();
will( returnValue( indexUrl ) );
allowing( tempContext ).getIndexCreators();
will( returnValue( DEFAULT_CREATORS ) );
allowing( tempContext ).commit();
oneOf( mockFetcher ).connect( repositoryId, indexUrl );
oneOf( mockFetcher ).retrieve( //
with( IndexingContext.INDEX_REMOTE_PROPERTIES_FILE ) );
will( new PropertiesAction()
{
@Override
Properties getProperties()
{
Properties properties = new Properties();
properties.setProperty( IndexingContext.INDEX_ID, "central" );
properties.setProperty( IndexingContext.INDEX_TIMESTAMP, "20081129174241.859 -0600" );
properties.setProperty( IndexingContext.INDEX_CHUNK_COUNTER, "3" );
properties.setProperty( IndexingContext.INDEX_CHAIN_ID, "someid" );
properties.setProperty( IndexingContext.INDEX_CHUNK_PREFIX + "0", "3" );
properties.setProperty( IndexingContext.INDEX_CHUNK_PREFIX + "1", "2" );
properties.setProperty( IndexingContext.INDEX_CHUNK_PREFIX + "2", "1" );
return properties;
}
} );
allowing( tempContext ).getIndexDirectoryFile();
will( new IndexDirectoryFileAction( localProps, testBasedir ) );
never( mockFetcher ).retrieve( //
with( IndexingContext.INDEX_FILE_PREFIX + ".gz" ) );
// could create index archive there and verify that it is merged correctly
never( mockFetcher ).retrieve( //
with( IndexingContext.INDEX_FILE_PREFIX + ".1.gz" ) );
never( mockFetcher ).retrieve( //
with( IndexingContext.INDEX_FILE_PREFIX + ".2.gz" ) );
never( mockFetcher ).retrieve( //
with( IndexingContext.INDEX_FILE_PREFIX + ".3.gz" ) );
never( tempContext ).merge( with( any( Directory.class ) ) );
never( tempContext ).replace( with( any( Directory.class ) ) );
oneOf( mockFetcher ).disconnect();
}
} );
// tempContext.updateTimestamp( true, contextTimestamp );
IndexUpdateRequest updateRequest = new IndexUpdateRequest( tempContext, mockFetcher );
updater.fetchAndUpdateIndex( updateRequest );
mockery.assertIsSatisfied();
}