kickMonitor( monitor );
Collection<Topology> topologies = provider.getTopologies();
assertThat( topologies, notNullValue() );
assertThat( topologies.size(), is( 1 ) );
Topology topology = topologies.iterator().next();
assertThat( topology.getName(), is( "one" ) );
assertThat( topology.getTimestamp(), is( time ) );
assertThat( topoListener.events.size(), is( 1 ) );
topoListener.events.clear();
// Add a file to the directory.
File two = createFile( dir, "two.xml", "org/apache/hadoop/gateway/topology/file/topology-two.xml", 1L );
kickMonitor( monitor );
topologies = provider.getTopologies();
assertThat( topologies.size(), is( 2 ) );
Set<String> names = new HashSet<String>( Arrays.asList( "one", "two" ) );
Iterator<Topology> iterator = topologies.iterator();
topology = iterator.next();
assertThat( names, hasItem( topology.getName() ) );
names.remove( topology.getName() );
topology = iterator.next();
assertThat( names, hasItem( topology.getName() ) );
names.remove( topology.getName() );
assertThat( names.size(), is( 0 ) );
assertThat( topoListener.events.size(), is( 1 ) );
List<TopologyEvent> events = topoListener.events.get( 0 );
assertThat( events.size(), is( 1 ) );
TopologyEvent event = events.get( 0 );
assertThat( event.getType(), is( TopologyEvent.Type.CREATED ) );
assertThat( event.getTopology(), notNullValue() );
// Update a file in the directory.
two = createFile( dir, "two.xml", "org/apache/hadoop/gateway/topology/file/topology-three.xml", 2L );
kickMonitor( monitor );
topologies = provider.getTopologies();
assertThat( topologies.size(), is( 2 ) );
names = new HashSet<String>( Arrays.asList( "one", "two" ) );
iterator = topologies.iterator();
topology = iterator.next();
assertThat( names, hasItem( topology.getName() ) );
names.remove( topology.getName() );
topology = iterator.next();
assertThat( names, hasItem( topology.getName() ) );
names.remove( topology.getName() );
assertThat( names.size(), is( 0 ) );
// Remove a file from the directory.
two.delete();
kickMonitor( monitor );
topologies = provider.getTopologies();
assertThat( topologies.size(), is( 1 ) );
topology = topologies.iterator().next();
assertThat( topology.getName(), is( "one" ) );
assertThat( topology.getTimestamp(), is( time ) );
} finally {
FileUtils.deleteQuietly( dir );
}
}