@@ -1184,10 +1184,8 @@ public void testPutKeyWithReplicationConfig(String replicationValue,
1184
1184
ReplicationConfig replicationConfig =
1185
1185
new ECReplicationConfig (replicationValue );
1186
1186
if (isValidReplicationConfig ) {
1187
- OzoneOutputStream out = bucket .createKey (keyName ,
1188
- value .getBytes (UTF_8 ).length , replicationConfig , new HashMap <>());
1189
- out .write (value .getBytes (UTF_8 ));
1190
- out .close ();
1187
+ TestDataUtil .createKey (bucket , keyName ,
1188
+ replicationConfig , value .getBytes (UTF_8 ));
1191
1189
OzoneKey key = bucket .getKey (keyName );
1192
1190
assertEquals (keyName , key .getName ());
1193
1191
try (OzoneInputStream is = bucket .readKey (keyName )) {
@@ -1217,11 +1215,9 @@ public void testPutKey() throws IOException {
1217
1215
for (int i = 0 ; i < 10 ; i ++) {
1218
1216
String keyName = UUID .randomUUID ().toString ();
1219
1217
1220
- OzoneOutputStream out = bucket .createKey (keyName ,
1221
- value .getBytes (UTF_8 ).length , RATIS ,
1222
- ONE , new HashMap <>());
1223
- out .write (value .getBytes (UTF_8 ));
1224
- out .close ();
1218
+ TestDataUtil .createKey (bucket , keyName ,
1219
+ ReplicationConfig .fromTypeAndFactor (RATIS , ONE ),
1220
+ value .getBytes (UTF_8 ));
1225
1221
OzoneKey key = bucket .getKey (keyName );
1226
1222
assertEquals (keyName , key .getName ());
1227
1223
try (OzoneInputStream is = bucket .readKey (keyName )) {
@@ -1995,10 +1991,9 @@ public void testValidateBlockLengthWithCommitKey() throws IOException {
1995
1991
String keyName = UUID .randomUUID ().toString ();
1996
1992
1997
1993
// create the initial key with size 0, write will allocate the first block.
1998
- OzoneOutputStream out = bucket .createKey (keyName , 0 ,
1999
- RATIS , ONE , new HashMap <>());
2000
- out .write (value .getBytes (UTF_8 ));
2001
- out .close ();
1994
+ TestDataUtil .createKey (bucket , keyName ,
1995
+ ReplicationConfig .fromTypeAndFactor (RATIS , ONE ),
1996
+ value .getBytes (UTF_8 ));
2002
1997
OmKeyArgs .Builder builder = new OmKeyArgs .Builder ();
2003
1998
builder .setVolumeName (volumeName ).setBucketName (bucketName )
2004
1999
.setKeyName (keyName );
@@ -2030,11 +2025,9 @@ public void testPutKeyRatisOneNode() throws IOException {
2030
2025
for (int i = 0 ; i < 10 ; i ++) {
2031
2026
String keyName = UUID .randomUUID ().toString ();
2032
2027
2033
- OzoneOutputStream out = bucket .createKey (keyName ,
2034
- value .getBytes (UTF_8 ).length , ReplicationType .RATIS ,
2035
- ONE , new HashMap <>());
2036
- out .write (value .getBytes (UTF_8 ));
2037
- out .close ();
2028
+ TestDataUtil .createKey (bucket , keyName ,
2029
+ ReplicationConfig .fromTypeAndFactor (RATIS , ONE ),
2030
+ value .getBytes (UTF_8 ));
2038
2031
OzoneKey key = bucket .getKey (keyName );
2039
2032
assertEquals (keyName , key .getName ());
2040
2033
try (OzoneInputStream is = bucket .readKey (keyName )) {
@@ -2065,11 +2058,9 @@ public void testPutKeyRatisThreeNodes() throws IOException {
2065
2058
for (int i = 0 ; i < 10 ; i ++) {
2066
2059
String keyName = UUID .randomUUID ().toString ();
2067
2060
2068
- OzoneOutputStream out = bucket .createKey (keyName ,
2069
- value .getBytes (UTF_8 ).length , ReplicationType .RATIS ,
2070
- THREE , new HashMap <>());
2071
- out .write (value .getBytes (UTF_8 ));
2072
- out .close ();
2061
+ TestDataUtil .createKey (bucket , keyName ,
2062
+ ReplicationConfig .fromTypeAndFactor (RATIS , THREE ),
2063
+ value .getBytes (UTF_8 ));
2073
2064
OzoneKey key = bucket .getKey (keyName );
2074
2065
assertEquals (keyName , key .getName ());
2075
2066
try (OzoneInputStream is = bucket .readKey (keyName )) {
@@ -2107,11 +2098,9 @@ public void testPutKeyRatisThreeNodesParallel() throws IOException,
2107
2098
String keyName = UUID .randomUUID ().toString ();
2108
2099
String data = Arrays .toString (generateData (5 * 1024 * 1024 ,
2109
2100
(byte ) RandomUtils .nextLong ()));
2110
- OzoneOutputStream out = bucket .createKey (keyName ,
2111
- data .getBytes (UTF_8 ).length , ReplicationType .RATIS ,
2112
- THREE , new HashMap <>());
2113
- out .write (data .getBytes (UTF_8 ));
2114
- out .close ();
2101
+ TestDataUtil .createKey (bucket , keyName ,
2102
+ ReplicationConfig .fromTypeAndFactor (RATIS , THREE ),
2103
+ data .getBytes (UTF_8 ));
2115
2104
OzoneKey key = bucket .getKey (keyName );
2116
2105
assertEquals (keyName , key .getName ());
2117
2106
try (OzoneInputStream is = bucket .readKey (keyName )) {
@@ -2185,11 +2174,9 @@ private void createAndCorruptKey(String volumeName, String bucketName,
2185
2174
OzoneBucket bucket = volume .getBucket (bucketName );
2186
2175
2187
2176
// Write data into a key
2188
- OzoneOutputStream out = bucket .createKey (keyName ,
2189
- value .getBytes (UTF_8 ).length , ReplicationType .RATIS ,
2190
- ONE , new HashMap <>());
2191
- out .write (value .getBytes (UTF_8 ));
2192
- out .close ();
2177
+ TestDataUtil .createKey (bucket , keyName ,
2178
+ ReplicationConfig .fromTypeAndFactor (RATIS , ONE ),
2179
+ value .getBytes (UTF_8 ));
2193
2180
2194
2181
// We need to find the location of the chunk file corresponding to the
2195
2182
// data we just wrote.
@@ -2247,11 +2234,9 @@ public void testGetKeyDetails() throws IOException {
2247
2234
String keyValue = RandomStringUtils .random (128 );
2248
2235
//String keyValue = "this is a test value.glx";
2249
2236
// create the initial key with size 0, write will allocate the first block.
2250
- OzoneOutputStream out = bucket .createKey (keyName ,
2251
- keyValue .getBytes (UTF_8 ).length , RATIS ,
2252
- ONE , new HashMap <>());
2253
- out .write (keyValue .getBytes (UTF_8 ));
2254
- out .close ();
2237
+ TestDataUtil .createKey (bucket , keyName ,
2238
+ ReplicationConfig .fromTypeAndFactor (RATIS , ONE ),
2239
+ keyValue .getBytes (UTF_8 ));
2255
2240
2256
2241
// First, confirm the key info from the client matches the info in OM.
2257
2242
OmKeyArgs .Builder builder = new OmKeyArgs .Builder ();
@@ -2342,11 +2327,9 @@ public void testReadKeyWithCorruptedData() throws IOException {
2342
2327
String keyName = UUID .randomUUID ().toString ();
2343
2328
2344
2329
// Write data into a key
2345
- OzoneOutputStream out = bucket .createKey (keyName ,
2346
- value .getBytes (UTF_8 ).length , ReplicationType .RATIS ,
2347
- ONE , new HashMap <>());
2348
- out .write (value .getBytes (UTF_8 ));
2349
- out .close ();
2330
+ TestDataUtil .createKey (bucket , keyName ,
2331
+ ReplicationConfig .fromTypeAndFactor (RATIS , ONE ),
2332
+ value .getBytes (UTF_8 ));
2350
2333
2351
2334
// We need to find the location of the chunk file corresponding to the
2352
2335
// data we just wrote.
@@ -2393,20 +2376,16 @@ void testZReadKeyWithUnhealthyContainerReplica() throws Exception {
2393
2376
String keyName1 = UUID .randomUUID ().toString ();
2394
2377
2395
2378
// Write first key
2396
- OzoneOutputStream out = bucket .createKey (keyName1 ,
2397
- value .getBytes (UTF_8 ).length , ReplicationType .RATIS ,
2398
- THREE , new HashMap <>());
2399
- out .write (value .getBytes (UTF_8 ));
2400
- out .close ();
2379
+ TestDataUtil .createKey (bucket , keyName1 ,
2380
+ ReplicationConfig .fromTypeAndFactor (RATIS , THREE ),
2381
+ value .getBytes (UTF_8 ));
2401
2382
2402
2383
// Write second key
2403
2384
String keyName2 = UUID .randomUUID ().toString ();
2404
2385
value = "unhealthy container replica" ;
2405
- out = bucket .createKey (keyName2 ,
2406
- value .getBytes (UTF_8 ).length , ReplicationType .RATIS ,
2407
- THREE , new HashMap <>());
2408
- out .write (value .getBytes (UTF_8 ));
2409
- out .close ();
2386
+ TestDataUtil .createKey (bucket , keyName2 ,
2387
+ ReplicationConfig .fromTypeAndFactor (RATIS , THREE ),
2388
+ value .getBytes (UTF_8 ));
2410
2389
2411
2390
// Find container ID
2412
2391
OzoneKey key = bucket .getKey (keyName2 );
@@ -2491,11 +2470,9 @@ void testReadKeyWithCorruptedDataWithMutiNodes() throws IOException {
2491
2470
String keyName = UUID .randomUUID ().toString ();
2492
2471
2493
2472
// Write data into a key
2494
- OzoneOutputStream out = bucket .createKey (keyName ,
2495
- value .getBytes (UTF_8 ).length , ReplicationType .RATIS ,
2496
- THREE , new HashMap <>());
2497
- out .write (value .getBytes (UTF_8 ));
2498
- out .close ();
2473
+ TestDataUtil .createKey (bucket , keyName ,
2474
+ ReplicationConfig .fromTypeAndFactor (RATIS , THREE ),
2475
+ value .getBytes (UTF_8 ));
2499
2476
2500
2477
// We need to find the location of the chunk file corresponding to the
2501
2478
// data we just wrote.
@@ -2560,11 +2537,9 @@ public void testDeleteKey()
2560
2537
OzoneVolume volume = store .getVolume (volumeName );
2561
2538
volume .createBucket (bucketName );
2562
2539
OzoneBucket bucket = volume .getBucket (bucketName );
2563
- OzoneOutputStream out = bucket .createKey (keyName ,
2564
- value .getBytes (UTF_8 ).length , RATIS ,
2565
- ONE , new HashMap <>());
2566
- out .write (value .getBytes (UTF_8 ));
2567
- out .close ();
2540
+ TestDataUtil .createKey (bucket , keyName ,
2541
+ ReplicationConfig .fromTypeAndFactor (RATIS , ONE ),
2542
+ value .getBytes (UTF_8 ));
2568
2543
OzoneKey key = bucket .getKey (keyName );
2569
2544
assertEquals (keyName , key .getName ());
2570
2545
bucket .deleteKey (keyName );
@@ -2853,30 +2828,18 @@ public void testListKey()
2853
2828
String keyBaseA = "key-a-" ;
2854
2829
for (int i = 0 ; i < 10 ; i ++) {
2855
2830
byte [] value = RandomStringUtils .randomAscii (10240 ).getBytes (UTF_8 );
2856
- OzoneOutputStream one = volAbucketA .createKey (
2831
+ TestDataUtil .createKey (volAbucketA ,
2857
2832
keyBaseA + i + "-" + RandomStringUtils .randomNumeric (5 ),
2858
- value .length , RATIS , ONE ,
2859
- new HashMap <>());
2860
- one .write (value );
2861
- one .close ();
2862
- OzoneOutputStream two = volAbucketB .createKey (
2833
+ ReplicationConfig .fromTypeAndFactor (RATIS , ONE ), value );
2834
+ TestDataUtil .createKey (volAbucketB ,
2863
2835
keyBaseA + i + "-" + RandomStringUtils .randomNumeric (5 ),
2864
- value .length , RATIS , ONE ,
2865
- new HashMap <>());
2866
- two .write (value );
2867
- two .close ();
2868
- OzoneOutputStream three = volBbucketA .createKey (
2836
+ ReplicationConfig .fromTypeAndFactor (RATIS , ONE ), value );
2837
+ TestDataUtil .createKey (volBbucketA ,
2869
2838
keyBaseA + i + "-" + RandomStringUtils .randomNumeric (5 ),
2870
- value .length , RATIS , ONE ,
2871
- new HashMap <>());
2872
- three .write (value );
2873
- three .close ();
2874
- OzoneOutputStream four = volBbucketB .createKey (
2839
+ ReplicationConfig .fromTypeAndFactor (RATIS , ONE ), value );
2840
+ TestDataUtil .createKey (volBbucketB ,
2875
2841
keyBaseA + i + "-" + RandomStringUtils .randomNumeric (5 ),
2876
- value .length , RATIS , ONE ,
2877
- new HashMap <>());
2878
- four .write (value );
2879
- four .close ();
2842
+ ReplicationConfig .fromTypeAndFactor (RATIS , ONE ), value );
2880
2843
}
2881
2844
/*
2882
2845
Create 10 keys in vol-a-<random>/buc-a-<random>,
@@ -2886,30 +2849,18 @@ public void testListKey()
2886
2849
String keyBaseB = "key-b-" ;
2887
2850
for (int i = 0 ; i < 10 ; i ++) {
2888
2851
byte [] value = RandomStringUtils .randomAscii (10240 ).getBytes (UTF_8 );
2889
- OzoneOutputStream one = volAbucketA .createKey (
2852
+ TestDataUtil .createKey (volAbucketA ,
2890
2853
keyBaseB + i + "-" + RandomStringUtils .randomNumeric (5 ),
2891
- value .length , RATIS , ONE ,
2892
- new HashMap <>());
2893
- one .write (value );
2894
- one .close ();
2895
- OzoneOutputStream two = volAbucketB .createKey (
2854
+ ReplicationConfig .fromTypeAndFactor (RATIS , ONE ), value );
2855
+ TestDataUtil .createKey (volAbucketB ,
2896
2856
keyBaseB + i + "-" + RandomStringUtils .randomNumeric (5 ),
2897
- value .length , RATIS , ONE ,
2898
- new HashMap <>());
2899
- two .write (value );
2900
- two .close ();
2901
- OzoneOutputStream three = volBbucketA .createKey (
2857
+ ReplicationConfig .fromTypeAndFactor (RATIS , ONE ), value );
2858
+ TestDataUtil .createKey (volBbucketA ,
2902
2859
keyBaseB + i + "-" + RandomStringUtils .randomNumeric (5 ),
2903
- value .length , RATIS , ONE ,
2904
- new HashMap <>());
2905
- three .write (value );
2906
- three .close ();
2907
- OzoneOutputStream four = volBbucketB .createKey (
2860
+ ReplicationConfig .fromTypeAndFactor (RATIS , ONE ), value );
2861
+ TestDataUtil .createKey (volBbucketB ,
2908
2862
keyBaseB + i + "-" + RandomStringUtils .randomNumeric (5 ),
2909
- value .length , RATIS , ONE ,
2910
- new HashMap <>());
2911
- four .write (value );
2912
- four .close ();
2863
+ ReplicationConfig .fromTypeAndFactor (RATIS , ONE ), value );
2913
2864
}
2914
2865
Iterator <? extends OzoneKey > volABucketAIter =
2915
2866
volAbucketA .listKeys ("key-" );
@@ -3349,10 +3300,9 @@ public void testClientLeakDetector() throws Exception {
3349
3300
OzoneBucket bucket = volume .getBucket (bucketName );
3350
3301
byte [] data = new byte [10 ];
3351
3302
Arrays .fill (data , (byte ) 1 );
3352
- try (OzoneOutputStream out = bucket .createKey (keyName , 10 ,
3353
- ReplicationConfig .fromTypeAndFactor (RATIS , ONE ), new HashMap <>())) {
3354
- out .write (data );
3355
- }
3303
+ TestDataUtil .createKey (bucket , keyName ,
3304
+ ReplicationConfig .fromTypeAndFactor (RATIS , ONE ),
3305
+ data );
3356
3306
client = null ;
3357
3307
System .gc ();
3358
3308
GenericTestUtils .waitFor (() -> ozoneClientFactoryLogCapturer .getOutput ()
@@ -4244,10 +4194,9 @@ private void validateOzoneAccessAcl(OzoneObj ozObj) throws IOException {
4244
4194
}
4245
4195
4246
4196
private void writeKey (String key1 , OzoneBucket bucket ) throws IOException {
4247
- OzoneOutputStream out = bucket .createKey (key1 , 1024 , RATIS ,
4248
- ONE , new HashMap <>());
4249
- out .write (RandomStringUtils .random (1024 ).getBytes (UTF_8 ));
4250
- out .close ();
4197
+ TestDataUtil .createKey (bucket , key1 ,
4198
+ ReplicationConfig .fromTypeAndFactor (RATIS , ONE ),
4199
+ RandomStringUtils .random (1024 ).getBytes (UTF_8 ));
4251
4200
}
4252
4201
4253
4202
private byte [] generateData (int size , byte val ) {
@@ -4621,10 +4570,8 @@ public void testHeadObject() throws IOException {
4621
4570
4622
4571
String keyName = UUID .randomUUID ().toString ();
4623
4572
4624
- OzoneOutputStream out = bucket .createKey (keyName ,
4625
- value .getBytes (UTF_8 ).length , replicationConfig , new HashMap <>());
4626
- out .write (value .getBytes (UTF_8 ));
4627
- out .close ();
4573
+ TestDataUtil .createKey (bucket , keyName ,
4574
+ replicationConfig , value .getBytes (UTF_8 ));
4628
4575
4629
4576
OzoneKey key = bucket .headObject (keyName );
4630
4577
assertEquals (volumeName , key .getVolumeName ());
@@ -4666,16 +4613,12 @@ private void createRequiredForVersioningTest(String volumeName,
4666
4613
.setBucketLayout (BucketLayout .OBJECT_STORE ).build ());
4667
4614
OzoneBucket bucket = volume .getBucket (bucketName );
4668
4615
4669
- OzoneOutputStream out = bucket .createKey (keyName ,
4670
- value .getBytes (UTF_8 ).length , replicationConfig , new HashMap <>());
4671
- out .write (value .getBytes (UTF_8 ));
4672
- out .close ();
4616
+ TestDataUtil .createKey (bucket , keyName ,
4617
+ replicationConfig , value .getBytes (UTF_8 ));
4673
4618
4674
4619
// Override key
4675
- out = bucket .createKey (keyName ,
4676
- value .getBytes (UTF_8 ).length , replicationConfig , new HashMap <>());
4677
- out .write (value .getBytes (UTF_8 ));
4678
- out .close ();
4620
+ TestDataUtil .createKey (bucket , keyName ,
4621
+ replicationConfig , value .getBytes (UTF_8 ));
4679
4622
}
4680
4623
4681
4624
private void checkExceptedResultForVersioningTest (String volumeName ,
@@ -4896,11 +4839,9 @@ void testGetKeyAndFileWithNetworkTopology() throws IOException {
4896
4839
String keyName = UUID .randomUUID ().toString ();
4897
4840
4898
4841
// Write data into a key
4899
- try (OzoneOutputStream out = bucket .createKey (keyName ,
4900
- value .getBytes (UTF_8 ).length , ReplicationConfig .fromTypeAndFactor (
4901
- ReplicationType .RATIS , THREE ), new HashMap <>())) {
4902
- out .write (value .getBytes (UTF_8 ));
4903
- }
4842
+ TestDataUtil .createKey (bucket , keyName ,
4843
+ ReplicationConfig .fromTypeAndFactor (RATIS , THREE ),
4844
+ value .getBytes (UTF_8 ));
4904
4845
4905
4846
// Since the rpc client is outside of cluster, then getFirstNode should be
4906
4847
// equal to getClosestNode.
@@ -5181,10 +5122,8 @@ public void testPutObjectTagging(BucketLayout bucketLayout) throws Exception {
5181
5122
5182
5123
String keyName = UUID .randomUUID ().toString ();
5183
5124
5184
- OzoneOutputStream out = bucket .createKey (keyName ,
5185
- value .getBytes (UTF_8 ).length , anyReplication (), new HashMap <>());
5186
- out .write (value .getBytes (UTF_8 ));
5187
- out .close ();
5125
+ TestDataUtil .createKey (bucket , keyName ,
5126
+ anyReplication (), value .getBytes (UTF_8 ));
5188
5127
5189
5128
OzoneKey key = bucket .getKey (keyName );
5190
5129
assertTrue (key .getTags ().isEmpty ());
0 commit comments