}
@Test
public void testBatch() throws IOException, InterruptedException {
final Path init = ioService.get( URI.create( "git://amend-repo-test/readme.txt" ) );
final WatchService ws = init.getFileSystem().newWatchService();
ioService.write( init, "init!", new CommentedOption( "User Tester", "message1" ) );
ioService.write( init, "init 2!", new CommentedOption( "User Tester", "message2" ) );
{
List<WatchEvent<?>> events = ws.poll().pollEvents();
assertEquals( 1, events.size() );//modify readme
}
final Path init2 = ioService.get( URI.create( "git://amend-repo-test/readme2.txt" ) );
ioService.write( init2, "init 3!", new CommentedOption( "User Tester", "message3" ) );
{
List<WatchEvent<?>> events = ws.poll().pollEvents();
assertEquals( 1, events.size() ); // add file
}
ioService.write( init2, "init 4!", new CommentedOption( "User Tester", "message4" ) );
{
List<WatchEvent<?>> events = ws.poll().pollEvents();
assertEquals( 1, events.size() );// modify file
}
final VersionAttributeView vinit = ioService.getFileAttributeView( init, VersionAttributeView.class );
final VersionAttributeView vinit2 = ioService.getFileAttributeView( init, VersionAttributeView.class );
assertEquals( "init 2!", ioService.readAllString( init ) );
assertNotNull( vinit );
assertEquals( 2, vinit.readAttributes().history().records().size() );
assertNotNull( vinit2 );
assertEquals( 2, vinit2.readAttributes().history().records().size() );
ioService.startBatch( new FileSystem[]{ init.getFileSystem() } );
final Path path = ioService.get( URI.create( "git://amend-repo-test/mybatch" + new Random( 10L ).nextInt() + ".txt" ) );
final Path path2 = ioService.get( URI.create( "git://amend-repo-test/mybatch2" + new Random( 10L ).nextInt() + ".txt" ) );
ioService.write( path, "ooooo!" );
//init.file event
assertNotNull( ws.poll() );
ioService.write( path, "ooooo wdfs fg sdf!" );
assertNull( ws.poll() );
ioService.write( path2, "ooooo222!" );
assertNull( ws.poll() );
ioService.write( path2, " sdfsdg sdg ooooo222!" );
assertNull( ws.poll() );
ioService.endBatch();
{
List<WatchEvent<?>> events = ws.poll().pollEvents();
assertEquals( 2, events.size() ); //adds files
}
final VersionAttributeView v = ioService.getFileAttributeView( path, VersionAttributeView.class );
final VersionAttributeView v2 = ioService.getFileAttributeView( path2, VersionAttributeView.class );