1 24 25 package org.objectweb.cjdbc.scenario.standalone.socket; 26 27 import java.util.Enumeration ; 28 import java.util.ResourceBundle ; 29 30 import org.objectweb.cjdbc.scenario.templates.NoTemplate; 31 32 37 public class UTFWithSocketTest extends NoTemplate 38 { 39 40 41 46 public void testUTFOverSocketWithImage() throws Exception 47 { 48 ResourceBundle rb = ResourceBundle.getBundle("socketTest"); 50 Enumeration enu = rb.getKeys(); 51 String key; 52 while (enu.hasMoreElements()) 53 { 54 key = (String ) enu.nextElement(); 55 System.out.println("Using test property <" + key + "> with value <" 56 + rb.getObject(key) + ">"); 57 } 58 int serverPort = Integer.parseInt(rb.getString("serverPort")); 59 String imageFile = rb.getString("imageFile"); 60 int numberOfLoop = Integer.parseInt(rb.getString("numberOfLoop")); 61 String serverName = rb.getString("serverName"); 62 boolean useBufferedStream = new Boolean (rb.getString("useBufferedStream")) 63 .booleanValue(); 64 boolean useWriteObject = new Boolean (rb.getString("useWriteObject")) 65 .booleanValue(); 66 boolean useSameObject = new Boolean (rb.getString("useSameObject")) 67 .booleanValue(); 68 boolean useGC = new Boolean (rb.getString("useGC")).booleanValue(); 69 boolean useReset = new Boolean (rb.getString("useReset")).booleanValue(); 70 71 UTFClient cutf = new UTFClient(); 73 cutf.setServerPort(serverPort); 74 cutf.setLoop(numberOfLoop); 75 cutf.setImageFile(imageFile); 76 cutf.setServerName(serverName); 77 cutf.setUseBufferedStream(useBufferedStream); 78 cutf.setUseWriteObject(useWriteObject); 79 cutf.setUseGC(useGC); 80 cutf.setUseSameObject(useSameObject); 81 cutf.setUseReset(useReset); 82 83 UTFServer sutf = new UTFServer(); 85 sutf.setServerPort(serverPort); 86 87 long started = System.currentTimeMillis(); 89 long freeStart = Runtime.getRuntime().freeMemory(); 90 Thread server = new Thread (sutf); 91 Thread client = new Thread (cutf); 92 server.start(); 93 client.start(); 94 95 server.join(); 97 client.join(); 98 long end = System.currentTimeMillis(); 99 long freeEnd = Runtime.getRuntime().freeMemory(); 100 long usedMemory = (freeEnd - freeStart); 101 long last = end - started; 102 long time = last/1000; 103 float average = (numberOfLoop / time); 104 105 System.out.println("The test lasted "+time+" s. ("+last+" ms.) for an average of "+average+" loop per second. "); 106 System.out.println("Used memory was:"+usedMemory/1024/1024+" Mb, "+usedMemory+" bytes."); 107 assertEquals(cutf.getHexa(),sutf.getHexa()); 108 } 109 } | Popular Tags |