Produced by Araxis Merge on 5/25/2018 9:21:43 AM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | C:\AraxisMergeCompare\Pri_un\ZIP\DSM-cif\Direct Implementation\java\install\build\download\apache-tomcat-6.0.37.tar\apache-tomcat-6.0.37\bin\tomcat-native.tar\tomcat-native\tomcat-native-1.1.27-src\jni\test\org\apache\tomcat\jni | SocketServerTestSuite.java | Tue Feb 5 13:49:48 2013 UTC |
| 2 | C:\AraxisMergeCompare\Pri_re\ZIP\DSM-cif\Direct Implementation\java\install\build\download\apache-tomcat-6.0.37.tar\apache-tomcat-6.0.37\bin\tomcat-native.tar\tomcat-native\tomcat-native-1.1.27-src\jni\test\org\apache\tomcat\jni | SocketServerTestSuite.java | Thu May 24 19:44:38 2018 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 410 |
| Changed | 1 | 2 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | /* | |
| 2 | * License d to the A pache Soft ware Found ation (ASF ) under on e or more | |
| 3 | * contrib utor licen se agreeme nts. See the NOTICE file dist ributed wi th | |
| 4 | * this wo rk for add itional in formation regarding copyright ownership. | |
| 5 | * The ASF licenses this file to You und er the Apa che Licens e, Version 2.0 | |
| 6 | * (the "L icense"); you may no t use this file exce pt in comp liance wit h | |
| 7 | * the Lic ense. You may obtai n a copy o f the Lice nse at | |
| 8 | * | |
| 9 | * ht tp://www.a pache.org/ licenses/L ICENSE-2.0 | |
| 10 | * | |
| 11 | * Unless required b y applicab le law or agreed to in writing , software | |
| 12 | * distrib uted under the Licen se is dist ributed on an "AS IS " BASIS, | |
| 13 | * WITHOUT WARRANTIE S OR CONDI TIONS OF A NY KIND, e ither expr ess or imp lied. | |
| 14 | * See the License f or the spe cific lang uage gover ning permi ssions and | |
| 15 | * limitat ions under the Licen se. | |
| 16 | */ | |
| 17 | ||
| 18 | package or g.apache.t omcat.jni; | |
| 19 | ||
| 20 | import jun it.framewo rk.Test; | |
| 21 | import jun it.framewo rk.TestSui te; | |
| 22 | import jun it.textui. TestRunner ; | |
| 23 | import jun it.framewo rk.TestCas e; | |
| 24 | ||
| 25 | import jav a.io.Outpu tStream; | |
| 26 | ||
| 27 | /** | |
| 28 | * A basic test suit e that tes ts Socket Server fea ture. | |
| 29 | * | |
| 30 | * @author Jean-Fred eric Clere | |
| 31 | * @versio n $Id: Soc ketServerT estSuite.j ava 144258 7 2013-02- 05 13:49:4 8Z rjung $ | |
| 32 | * @see or g.apache.t omcat.jni | |
| 33 | */ | |
| 34 | public cla ss SocketS erverTestS uite exten ds TestCas e { | |
| 35 | ||
| 36 | privat e long ser verSock = 0; | |
| 37 | private in t port= PORT ; | |
| 38 | privat e String h ost="local host"; | |
| 39 | ||
| 40 | public static lo ng serverP ool = 0; | |
| 41 | ||
| 42 | public void test SocketServ erTestSuit e() throws Exception { | |
| 43 | ||
| 44 | /* Load APR library */ | |
| 45 | Li brary.init ialize(nul l); | |
| 46 | ||
| 47 | /* Create th e server s ocket and listen on it */ | |
| 48 | se rverPool = Pool.crea te(0); | |
| 49 | lo ng inetAdd ress = Add ress.info( host, Sock et.APR_INE T, | |
| 50 | port, 0, s erverPool) ; | |
| 51 | se rverSock = Socket.cr eate(Socke t.APR_INET , Socket.S OCK_STREAM , | |
| 52 | Socke t.APR_PROT O_TCP, ser verPool); | |
| 53 | in t rc = Soc ket.bind(s erverSock, inetAddre ss); | |
| 54 | if (rc != 0) { | |
| 55 | Socket.c lose(serve rSock); | |
| 56 | throw(ne w Exceptio n("Can't b ind: " + E rror.strer ror(rc))); | |
| 57 | } | |
| 58 | So cket.liste n(serverSo ck, 5); | |
| 59 | ||
| 60 | /* Start the client th at connect s to the s erver */ | |
| 61 | Cl ient clien t = new Cl ient(); | |
| 62 | cl ient.start (); | |
| 63 | ja va.lang.Th read.sleep (100); | |
| 64 | ||
| 65 | /* Accept it */ | |
| 66 | lo ng clientS ock = Sock et.accept( serverSock ); | |
| 67 | ||
| 68 | /* Try 2 mil liseconds timeout */ | |
| 69 | So cket.timeo utSet(clie ntSock, 20 00); | |
| 70 | lo ng timeout = Socket. timeoutGet (clientSoc k); | |
| 71 | if (timeout != 2000) { | |
| 72 | Socket.c lose(clien tSock); | |
| 73 | Socket.c lose(serve rSock); | |
| 74 | throw ne w Exceptio n("Socket. timeoutGet clientSoc k failed") ; | |
| 75 | } | |
| 76 | ||
| 77 | lo ng start = System.cu rrentTimeM illis(); | |
| 78 | by te [] buf = new byte [1]; | |
| 79 | wh ile (Socke t.recv(cli entSock, b uf, 0, 1) == 1) { | |
| 80 | } | |
| 81 | lo ng wait = System.cur rentTimeMi llis() - s tart; | |
| 82 | /* allow som e margin b etween set timeout a nd observe d return t ime */ | |
| 83 | if (wait < 1 || wait > 12) { | |
| 84 | Socket.c lose(clien tSock); | |
| 85 | Socket.c lose(serve rSock); | |
| 86 | throw ne w Exceptio n("2 milli seconds cl ient Socke t.timeoutS et failed" ); | |
| 87 | } | |
| 88 | ||
| 89 | /* Try 2 mil liseconds timeout on accept so cket */ | |
| 90 | So cket.timeo utSet(serv erSock, 20 00); | |
| 91 | ti meout = So cket.timeo utGet(serv erSock); | |
| 92 | if (timeout != 2000) { | |
| 93 | Socket.c lose(serve rSock); | |
| 94 | throw ne w Exceptio n("Socket. timeoutGet serverSoc k failed") ; | |
| 95 | } | |
| 96 | ||
| 97 | st art = Syst em.current TimeMillis (); | |
| 98 | bo olean ok = false; | |
| 99 | tr y { | |
| 100 | clientSo ck = Socke t.accept(s erverSock) ; | |
| 101 | } catch (Exc eption ex) { | |
| 102 | ok = tru e; | |
| 103 | } | |
| 104 | wa it = Syste m.currentT imeMillis( ) - start; | |
| 105 | /* allow som e margin b etween set timeout a nd observe d return t ime */ | |
| 106 | if (wait < 1 || wait > 12 && ! o k) { | |
| 107 | Socket.c lose(clien tSock); | |
| 108 | Socket.c lose(serve rSock); | |
| 109 | throw ne w Exceptio n("2 milli seconds ac cept Socke t.timeoutS et failed" ); | |
| 110 | } | |
| 111 | ||
| 112 | /* Try APR_S O_NONBLOCK */ | |
| 113 | So cket.optSe t(serverSo ck, Socket .APR_SO_NO NBLOCK, 1) ; | |
| 114 | in t val = So cket.optGe t(serverSo ck, Socket .APR_SO_NO NBLOCK); | |
| 115 | if (val != 1 ) { | |
| 116 | Socket.c lose(serve rSock); | |
| 117 | throw ne w Exceptio n("Socket. optGet ser verSock fa iled"); | |
| 118 | } | |
| 119 | ||
| 120 | st art = Syst em.current TimeMillis (); | |
| 121 | ok = false; | |
| 122 | tr y { | |
| 123 | clientSo ck = Socke t.accept(s erverSock) ; | |
| 124 | } catch (Exc eption ex) { | |
| 125 | ok = tru e; | |
| 126 | } | |
| 127 | wa it = Syste m.currentT imeMillis( ) - start; | |
| 128 | if (wait > 1 && ! ok) { | |
| 129 | Socket.c lose(clien tSock); | |
| 130 | Socket.c lose(serve rSock); | |
| 131 | throw ne w Exceptio n("non_blo cking acce pt Socket. APR_SO_NON BLOCK fail ed"); | |
| 132 | } | |
| 133 | cl ient.join( ); | |
| 134 | So cket.close (clientSoc k); | |
| 135 | ||
| 136 | /* Try the s ame on cli ent socket */ | |
| 137 | cl ient = new Client(); | |
| 138 | cl ient.start (); | |
| 139 | ja va.lang.Th read.sleep (100); | |
| 140 | cl ientSock = Socket.ac cept(serve rSock); | |
| 141 | So cket.optSe t(clientSo ck, Socket .APR_SO_NO NBLOCK, 1) ; | |
| 142 | va l = Socket .optGet(cl ientSock, Socket.APR _SO_NONBLO CK); | |
| 143 | if (val != 1 ) { | |
| 144 | Socket.c lose(clien tSock); | |
| 145 | Socket.c lose(serve rSock); | |
| 146 | throw ne w Exceptio n("Socket. optGet cli entSock fa iled"); | |
| 147 | } | |
| 148 | st art = Syst em.current TimeMillis (); | |
| 149 | wh ile (Socke t.recv(cli entSock, b uf, 0, 1) == 1) { | |
| 150 | } | |
| 151 | wa it = Syste m.currentT imeMillis( ) - start; | |
| 152 | if (wait > 1 ) { | |
| 153 | Socket.c lose(clien tSock); | |
| 154 | Socket.c lose(serve rSock); | |
| 155 | throw ne w Exceptio n("non_blo cking clie nt Socket. APR_SO_NON BLOCK fail ed"); | |
| 156 | } | |
| 157 | ||
| 158 | /* Now block ing */ | |
| 159 | So cket.optSe t(clientSo ck, Socket .APR_SO_NO NBLOCK, 0) ; | |
| 160 | st art = Syst em.current TimeMillis (); | |
| 161 | wh ile (Socke t.recv(cli entSock, b uf, 0, 1) == 1) { | |
| 162 | } | |
| 163 | wa it = Syste m.currentT imeMillis( ) - start; | |
| 164 | if (wait < 1 ) { | |
| 165 | Socket.c lose(clien tSock); | |
| 166 | Socket.c lose(serve rSock); | |
| 167 | throw ne w Exceptio n("non_blo cking clie nt Socket. APR_SO_NON BLOCK fals e failed") ; | |
| 168 | } | |
| 169 | ||
| 170 | cl ient.join( ); | |
| 171 | So cket.close (clientSoc k); | |
| 172 | So cket.close (serverSoc k); | |
| 173 | Li brary.term inate(); | |
| 174 | } | |
| 175 | ||
| 176 | /* sma ll client that conne cts and se nds one by te */ | |
| 177 | privat e class Cl ient exten ds java.la ng.Thread { | |
| 178 | ja va.net.Soc ket sock; | |
| 179 | pu blic Clien t() throws Exception { | |
| 180 | sock = n ew java.ne t.Socket(h ost, port) ; | |
| 181 | } | |
| 182 | pu blic void run() { | |
| 183 | try { | |
| 184 | Outp utStream o u = sock.g etOutputSt ream(); | |
| 185 | ou.w rite('A'); | |
| 186 | ou.f lush(); | |
| 187 | java .lang.Thre ad.sleep(1 0000); | |
| 188 | sock .close(); | |
| 189 | } catch( Exception ex ) { | |
| 190 | ex.p rintStackT race(); | |
| 191 | } | |
| 192 | } | |
| 193 | } | |
| 194 | ||
| 195 | public static vo id main(St ring[] arg s) { | |
| 196 | Te stRunner.r un(suite() ); | |
| 197 | } | |
| 198 | ||
| 199 | public static Te st suite() | |
| 200 | { | |
| 201 | Te stSuite su ite = new TestSuite( "Tomcat N ative Serv er Socket" ); | |
| 202 | su ite.addTes t(new Test Suite(Sock etServerTe stSuite.cl ass)); | |
| 203 | su ite.addTes t(new Test Suite(Sock etServerTe stBind.cla ss)); | |
| 204 | re turn suite ; | |
| 205 | } | |
| 206 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.