Skip to content

Commit 55f6924

Browse files
authored
HDDS-12845. Reuse TestDataUtil.createKey in OzoneRpcClientTests (#8274)
1 parent 8a4deeb commit 55f6924

File tree

1 file changed

+71
-132
lines changed

1 file changed

+71
-132
lines changed

hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/OzoneRpcClientTests.java

Lines changed: 71 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,10 +1184,8 @@ public void testPutKeyWithReplicationConfig(String replicationValue,
11841184
ReplicationConfig replicationConfig =
11851185
new ECReplicationConfig(replicationValue);
11861186
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));
11911189
OzoneKey key = bucket.getKey(keyName);
11921190
assertEquals(keyName, key.getName());
11931191
try (OzoneInputStream is = bucket.readKey(keyName)) {
@@ -1217,11 +1215,9 @@ public void testPutKey() throws IOException {
12171215
for (int i = 0; i < 10; i++) {
12181216
String keyName = UUID.randomUUID().toString();
12191217

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));
12251221
OzoneKey key = bucket.getKey(keyName);
12261222
assertEquals(keyName, key.getName());
12271223
try (OzoneInputStream is = bucket.readKey(keyName)) {
@@ -1995,10 +1991,9 @@ public void testValidateBlockLengthWithCommitKey() throws IOException {
19951991
String keyName = UUID.randomUUID().toString();
19961992

19971993
// 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));
20021997
OmKeyArgs.Builder builder = new OmKeyArgs.Builder();
20031998
builder.setVolumeName(volumeName).setBucketName(bucketName)
20041999
.setKeyName(keyName);
@@ -2030,11 +2025,9 @@ public void testPutKeyRatisOneNode() throws IOException {
20302025
for (int i = 0; i < 10; i++) {
20312026
String keyName = UUID.randomUUID().toString();
20322027

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));
20382031
OzoneKey key = bucket.getKey(keyName);
20392032
assertEquals(keyName, key.getName());
20402033
try (OzoneInputStream is = bucket.readKey(keyName)) {
@@ -2065,11 +2058,9 @@ public void testPutKeyRatisThreeNodes() throws IOException {
20652058
for (int i = 0; i < 10; i++) {
20662059
String keyName = UUID.randomUUID().toString();
20672060

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));
20732064
OzoneKey key = bucket.getKey(keyName);
20742065
assertEquals(keyName, key.getName());
20752066
try (OzoneInputStream is = bucket.readKey(keyName)) {
@@ -2107,11 +2098,9 @@ public void testPutKeyRatisThreeNodesParallel() throws IOException,
21072098
String keyName = UUID.randomUUID().toString();
21082099
String data = Arrays.toString(generateData(5 * 1024 * 1024,
21092100
(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));
21152104
OzoneKey key = bucket.getKey(keyName);
21162105
assertEquals(keyName, key.getName());
21172106
try (OzoneInputStream is = bucket.readKey(keyName)) {
@@ -2185,11 +2174,9 @@ private void createAndCorruptKey(String volumeName, String bucketName,
21852174
OzoneBucket bucket = volume.getBucket(bucketName);
21862175

21872176
// 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));
21932180

21942181
// We need to find the location of the chunk file corresponding to the
21952182
// data we just wrote.
@@ -2247,11 +2234,9 @@ public void testGetKeyDetails() throws IOException {
22472234
String keyValue = RandomStringUtils.random(128);
22482235
//String keyValue = "this is a test value.glx";
22492236
// 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));
22552240

22562241
// First, confirm the key info from the client matches the info in OM.
22572242
OmKeyArgs.Builder builder = new OmKeyArgs.Builder();
@@ -2342,11 +2327,9 @@ public void testReadKeyWithCorruptedData() throws IOException {
23422327
String keyName = UUID.randomUUID().toString();
23432328

23442329
// 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));
23502333

23512334
// We need to find the location of the chunk file corresponding to the
23522335
// data we just wrote.
@@ -2393,20 +2376,16 @@ void testZReadKeyWithUnhealthyContainerReplica() throws Exception {
23932376
String keyName1 = UUID.randomUUID().toString();
23942377

23952378
// 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));
24012382

24022383
// Write second key
24032384
String keyName2 = UUID.randomUUID().toString();
24042385
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));
24102389

24112390
// Find container ID
24122391
OzoneKey key = bucket.getKey(keyName2);
@@ -2491,11 +2470,9 @@ void testReadKeyWithCorruptedDataWithMutiNodes() throws IOException {
24912470
String keyName = UUID.randomUUID().toString();
24922471

24932472
// 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));
24992476

25002477
// We need to find the location of the chunk file corresponding to the
25012478
// data we just wrote.
@@ -2560,11 +2537,9 @@ public void testDeleteKey()
25602537
OzoneVolume volume = store.getVolume(volumeName);
25612538
volume.createBucket(bucketName);
25622539
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));
25682543
OzoneKey key = bucket.getKey(keyName);
25692544
assertEquals(keyName, key.getName());
25702545
bucket.deleteKey(keyName);
@@ -2853,30 +2828,18 @@ public void testListKey()
28532828
String keyBaseA = "key-a-";
28542829
for (int i = 0; i < 10; i++) {
28552830
byte[] value = RandomStringUtils.randomAscii(10240).getBytes(UTF_8);
2856-
OzoneOutputStream one = volAbucketA.createKey(
2831+
TestDataUtil.createKey(volAbucketA,
28572832
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,
28632835
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,
28692838
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,
28752841
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);
28802843
}
28812844
/*
28822845
Create 10 keys in vol-a-<random>/buc-a-<random>,
@@ -2886,30 +2849,18 @@ public void testListKey()
28862849
String keyBaseB = "key-b-";
28872850
for (int i = 0; i < 10; i++) {
28882851
byte[] value = RandomStringUtils.randomAscii(10240).getBytes(UTF_8);
2889-
OzoneOutputStream one = volAbucketA.createKey(
2852+
TestDataUtil.createKey(volAbucketA,
28902853
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,
28962856
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,
29022859
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,
29082862
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);
29132864
}
29142865
Iterator<? extends OzoneKey> volABucketAIter =
29152866
volAbucketA.listKeys("key-");
@@ -3349,10 +3300,9 @@ public void testClientLeakDetector() throws Exception {
33493300
OzoneBucket bucket = volume.getBucket(bucketName);
33503301
byte[] data = new byte[10];
33513302
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);
33563306
client = null;
33573307
System.gc();
33583308
GenericTestUtils.waitFor(() -> ozoneClientFactoryLogCapturer.getOutput()
@@ -4244,10 +4194,9 @@ private void validateOzoneAccessAcl(OzoneObj ozObj) throws IOException {
42444194
}
42454195

42464196
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));
42514200
}
42524201

42534202
private byte[] generateData(int size, byte val) {
@@ -4621,10 +4570,8 @@ public void testHeadObject() throws IOException {
46214570

46224571
String keyName = UUID.randomUUID().toString();
46234572

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));
46284575

46294576
OzoneKey key = bucket.headObject(keyName);
46304577
assertEquals(volumeName, key.getVolumeName());
@@ -4666,16 +4613,12 @@ private void createRequiredForVersioningTest(String volumeName,
46664613
.setBucketLayout(BucketLayout.OBJECT_STORE).build());
46674614
OzoneBucket bucket = volume.getBucket(bucketName);
46684615

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));
46734618

46744619
// 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));
46794622
}
46804623

46814624
private void checkExceptedResultForVersioningTest(String volumeName,
@@ -4896,11 +4839,9 @@ void testGetKeyAndFileWithNetworkTopology() throws IOException {
48964839
String keyName = UUID.randomUUID().toString();
48974840

48984841
// 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));
49044845

49054846
// Since the rpc client is outside of cluster, then getFirstNode should be
49064847
// equal to getClosestNode.
@@ -5181,10 +5122,8 @@ public void testPutObjectTagging(BucketLayout bucketLayout) throws Exception {
51815122

51825123
String keyName = UUID.randomUUID().toString();
51835124

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));
51885127

51895128
OzoneKey key = bucket.getKey(keyName);
51905129
assertTrue(key.getTags().isEmpty());

0 commit comments

Comments
 (0)