1 import java.io.*; 2 import jcifs.smb.*; 3 import jcifs.util.Hexdump; 4 import java.util.*; 5 6 public class Torture2 extends Thread { 7 8 SmbFile from, to; 9 10 Torture2( String from, String to ) throws Exception { 11 this.from = new SmbFile( from ); 12 this.to = new SmbFile( to ); 13 } 14 15 public void run() { 16 try { 17 copyAndVerify(); 18 } catch( Exception e ) { 19 e.printStackTrace(); 20 } 21 } 22 23 void compare( SmbFile f1, SmbFile f2 ) throws Exception { 24 try { 26 if( f1.isDirectory() && f2.isDirectory() ) { 27 SmbFile[] dirents = f1.listFiles(); 28 SmbFile f; 29 for( int i = 0; i < dirents.length; i++ ) { 30 f = new SmbFile( f2, dirents[i].getName() ); 31 compare( dirents[i], f ); 33 } 34 } 35 if( f1.isDirectory() != f2.isDirectory() ) { 36 System.err.println( "directory comparison failed: " + f1.getName() + ": " + f1.isDirectory() + " " + f2.isDirectory() ); 37 } 38 if( f1.isFile() != f2.isFile() ) { 39 System.err.println( "file comparison failed: " + f1.getName() + ": " + f1.isFile() + " " + f2.isFile() ); 40 } 41 if( f1.getType() != f2.getType() ) { 42 System.err.println( "type comparison failed: " + f1.getName() + " " + f2.getName() ); 43 } 44 if( f1.getName().equals( f2.getName() ) == false ) { 45 System.err.println( "name comparison failed: " + f1.getName() + " " + f2.getName() ); 46 } 47 if( f1.length() != f2.length() ) { 48 System.err.println( "length comparison failed: " + f1.getName() + ": " + f1.length() + " " + f2.length() ); 49 } 50 if( f1.getAttributes() != f2.getAttributes() ) { 51 System.err.println( "attribute comparison failed: " + f1.getName() + ": " + Hexdump.toHexString( f1.getAttributes(), 4 ) + " " + Hexdump.toHexString( f2.getAttributes(), 4 )); 52 } 53 if( Math.abs( f1.createTime() - f2.createTime() ) > 1000 ) { 54 System.err.println( "create time comparison failed: " + f1.getName() + ": " + f1.createTime() + " " + f2.createTime() ); 55 } 56 if( Math.abs( f1.lastModified() - f2.lastModified() ) > 1000 ) { 57 System.err.println( "last modified comparison failed: " + f1.getName() + ": " + f1.lastModified() + " " + f2.lastModified() ); 58 } 59 } catch( Exception x ) { 60 System.err.println( "Exception comparing: " + f1 + " | " + f2 ); 61 x.printStackTrace(); 62 } 63 } 64 65 void copyAndVerify() throws Exception { 66 from.copyTo( to ); 67 compare( from, to ); 68 } 69 70 public static void main( String [] argv ) throws Exception { 71 Properties prp; 72 Torture2[] threads; 73 String from, to; 74 int i; 75 76 if( argv.length < 1 ) { 77 System.err.println( "Torture2 <properties file>" ); 78 System.exit( 1 ); 79 } 80 81 prp = new Properties(); 82 prp.load( new FileInputStream( argv[0] )); 83 84 threads = new Torture2[10]; 85 86 for( i = 0; i < 10; i++ ) { 87 from = prp.getProperty( "thread." + i + ".from.url" ); 88 to = prp.getProperty( "thread." + i + ".to.url" ); 89 if( from == null || to == null ) { 90 break; 91 } 92 threads[i] = new Torture2( from, to ); 93 threads[i].start(); 94 Thread.sleep( 12345 ); 95 } 96 while( i-- > 0 ) { 97 threads[i].join(); 98 } 99 System.err.println( "Test complete" ); 100 } 101 } 102 103 | Popular Tags |