19
19
import java .nio .charset .Charset ;
20
20
import java .util .Date ;
21
21
import java .util .concurrent .*;
22
+ import java .util .concurrent .atomic .AtomicBoolean ;
22
23
23
24
public class FixBlockUploaderWithRecorderTest {
24
25
int blockSize = 1024 * 1024 * 8 ;
@@ -102,7 +103,7 @@ public void breakThenUpload(final ExecutorService pool1, final ExecutorService p
102
103
StringMap p = new StringMap ().put ("returnBody" , returnBody );
103
104
104
105
final String token = TestConfig .testAuth .uploadToken (bucket , expectKey , 3600 , p );
105
- final int [] t1Finished = { 0 } ;
106
+ final AtomicBoolean t1Finished = new AtomicBoolean ( false ) ;
106
107
107
108
Thread t1 = new Thread () {
108
109
@ Override
@@ -154,14 +155,14 @@ public void run() {
154
155
int it1Finished = 0 ;
155
156
for (; it1Finished < 1500 ; it1Finished ++) {
156
157
doSleep (100 );
157
- if (t1Finished [ 0 ] == 1 ) {
158
+ if (t1Finished . get () ) {
158
159
break ;
159
160
}
160
161
}
161
- System .out .println ("t1Finished[0] == 1 " + ( t1Finished [ 0 ] == 1 ) + " " + it1Finished );
162
+ System .out .println ("t1Finished.get() == true " + t1Finished . get ( ) + " " + it1Finished );
162
163
doSleep (1500 );
163
164
final FixBlockUploader .FileBlockData fbd2 = new FixBlockUploader .FileBlockData (blockSize , f );
164
- final int [] t2Finished = { 0 } ;
165
+ final AtomicBoolean t2Finished = new AtomicBoolean ( false ) ;
165
166
Thread t2 = new Thread () {
166
167
@ Override
167
168
public void run () {
@@ -197,11 +198,11 @@ public void run() {
197
198
int it2Finished = 0 ;
198
199
for (; it2Finished < 1500 ; it2Finished ++) {
199
200
doSleep (100 );
200
- if (t2Finished [ 0 ] == 1 ) {
201
+ if (t2Finished . get () ) {
201
202
break ;
202
203
}
203
204
}
204
- System .out .println ("t2Finished[0] == 1 " + ( t2Finished [ 0 ] == 1 ) + " " + it2Finished );
205
+ System .out .println ("t2Finished.get() == true " + t2Finished . get ( ) + " " + it2Finished );
205
206
doSleep (1500 );
206
207
System .out .println ("------ start 3, " + new Date ());
207
208
try {
@@ -232,7 +233,7 @@ public void run() {
232
233
}
233
234
234
235
private void upload (int idx , FixBlockUploader .FileBlockData fbd , String token , String expectKey ,
235
- final ExecutorService pool , int maxRunningBlock , final int [] tFinished , String etag ) {
236
+ final ExecutorService pool , int maxRunningBlock , final AtomicBoolean tFinished , String etag ) {
236
237
try {
237
238
System .out .println ("------ start " + idx + ", " + new Date ());
238
239
Response r = up .upload (fbd , new FixBlockUploader .StaticToken (token ), expectKey , null , pool ,
@@ -242,10 +243,10 @@ private void upload(int idx, FixBlockUploader.FileBlockData fbd, String token, S
242
243
assertEquals (expectKey , ret .key );
243
244
assertEquals (String .valueOf (fbd .size ()), ret .fsize );
244
245
assertEquals (etag , ret .hash );
245
- tFinished [ 0 ] = 1 ;
246
+ tFinished . set ( true ) ;
246
247
} catch (Exception e ) {
247
248
System .out .println ("======= end " + idx + ": " );
248
- tFinished [ 0 ] = 1 ;
249
+ tFinished . set ( true ) ;
249
250
e .printStackTrace ();
250
251
}
251
252
}
0 commit comments