1 import java.io.*; 2 import jcifs.smb.*; 3 import java.util.*; 4 5 class Worker extends Thread { 6 7 Torture1 t; 8 Exception e; 9 10 Worker( Torture1 t ) { 11 this.t = t; 12 e = null; 13 } 14 public void run() { 15 try { 16 t.torture(); 17 } catch( Exception e ) { 18 this.e = e; 19 } 20 } 21 } 22 23 public class Torture1 { 24 25 Properties prp; 26 27 Torture1( Properties prp ) { 28 this.prp = prp; 29 } 30 31 void compare( SmbFile f1, SmbFile f2 ) throws Exception { 32 if( f1.isDirectory() && f2.isDirectory() ) { 33 SmbFile[] dirents = f1.listFiles(); 34 SmbFile f; 35 for( int i = 0; i < dirents.length; i++ ) { 36 f = new SmbFile( f2, dirents[i].getName() ); 37 compare( dirents[i], f ); 38 } 39 } 40 if( f1.isDirectory() != f2.isDirectory() ) { 41 System.err.println( "directory comparison failed" ); 42 } 43 if( f1.isFile() != f2.isFile() ) { 44 System.err.println( "file comparison failed" ); 45 } 46 if( f1.getType() != f2.getType() ) { 47 System.err.println( "type comparison failed" ); 48 } 49 if( f1.getName().equals( f2.getName() ) == false ) { 50 System.err.println( "name comparison failed: " + f1.getName() + " " + f2.getName() ); 51 } 52 if( f1.length() != f2.length() ) { 53 System.err.println( "length comparison failed: " + f1.length() + " " + f2.length() ); 54 } 55 } 56 57 void torture() throws Exception { 58 String domain, username, password, server, share, directory; 59 NtlmPasswordAuthentication ntlm; 60 61 domain = prp.getProperty( "torture.dst.domain" ); 62 username = prp.getProperty( "torture.dst.username" ); 63 password = prp.getProperty( "torture.dst.password" ); 64 65 ntlm = new NtlmPasswordAuthentication( domain, username, password ); 66 67 server = prp.getProperty( "torture.dst.server" ); 68 share = prp.getProperty( "torture.dst.share" ); 69 directory = prp.getProperty( "torture.dst.directory" ); 70 71 SmbFile dst = new SmbFile( "smb://", ntlm ); 72 dst = new SmbFile( dst, server ); 73 dst = new SmbFile( dst, share ); 74 dst = new SmbFile( dst, directory ); 75 76 SmbFile src = new SmbFile( prp.getProperty( "torture.src.url" )); 77 78 System.err.println( src + " --> " + dst ); 79 System.in.read(); 80 81 if( dst.exists() ) { 82 dst.delete(); 83 } 84 src.copyTo( dst ); 85 System.err.println( "CopyTo done" ); 86 System.in.read(); 87 compare( src, dst ); 88 System.err.println( "Test Complete" ); 89 } 90 91 public static void main( String [] argv ) throws Exception { 92 Properties prp = new Properties(); 93 prp.load( new FileInputStream( "torture.prp" )); 94 Torture1 t = new Torture1( prp ); 95 Worker w = new Worker( t ); 96 w.start(); 97 w.join(); 98 if( w.e != null ) { 99 throw w.e; 100 } 101 } 102 } 103
| Popular Tags
|