Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.apache.hadoop.ozone.OzoneConsts.ETAG;
import static org.apache.hadoop.ozone.OzoneConsts.MD5_HASH;
import static org.apache.hadoop.ozone.OzoneConsts.OZONE_URI_SCHEME;
import static org.apache.hadoop.ozone.TestDataUtil.createKey;
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.NOT_A_FILE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -366,9 +367,9 @@ public void testListKeysWithNotNormalizedPath() throws Exception {
byte[] input = new byte[length];
Arrays.fill(input, (byte)96);

createKey(ozoneBucket, key1, 10, input);
createKey(ozoneBucket, key2, 10, input);
createKey(ozoneBucket, key3, 10, input);
createAndAssertKey(ozoneBucket, key1, 10, input);
createAndAssertKey(ozoneBucket, key2, 10, input);
createAndAssertKey(ozoneBucket, key3, 10, input);

// Iterator with key name as prefix.

Expand Down Expand Up @@ -413,18 +414,18 @@ private void checkKeyList(Iterator<? extends OzoneKey > ozoneKeyIterator,
assertEquals(keys, outputKeys);
}

private void createKey(OzoneBucket ozoneBucket, String key, int length,
byte[] input)
private void createAndAssertKey(OzoneBucket ozoneBucket, String key, int length, byte[] input)
throws Exception {

createKey(ozoneBucket, key, input);
// Read the key with given key name.
readKey(ozoneBucket, key, length, input);

OzoneOutputStream ozoneOutputStream =
ozoneBucket.createKey(key, length);
}

ozoneOutputStream.write(input);
ozoneOutputStream.write(input, 0, 10);
ozoneOutputStream.close();
private void readKey(OzoneBucket ozoneBucket, String key, int length, byte[] input)
throws Exception {

// Read the key with given key name.
OzoneInputStream ozoneInputStream = ozoneBucket.readKey(key);
byte[] read = new byte[length];
ozoneInputStream.read(read, 0, length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,28 +107,53 @@ public static OzoneVolume createVolume(OzoneClient client,

public static void createKey(OzoneBucket bucket, String keyName,
String content) throws IOException {
createKey(bucket, keyName, ReplicationFactor.ONE,
ReplicationType.RATIS, content.getBytes(UTF_8));
}

public static void createKey(OzoneBucket bucket, String keyName,
byte[] content) throws IOException {
createKey(bucket, keyName, ReplicationFactor.ONE,
ReplicationType.RATIS, content);

}

public static void createKey(OzoneBucket bucket, String keyName,
ReplicationFactor repFactor, ReplicationType repType, String content)
ReplicationFactor repFactor, ReplicationType repType, byte[] content)
throws IOException {
ReplicationConfig repConfig = ReplicationConfig
.fromTypeAndFactor(repType, repFactor);
createKey(bucket, keyName, repConfig, content);
try (OutputStream stream = bucket
.createKey(keyName, content.length, repConfig,
new HashMap<>())) {
stream.write(content);
}
}

public static void createKey(OzoneBucket bucket, String keyName,
ReplicationConfig repConfig, String content)
ReplicationConfig repConfig, byte[] content)
throws IOException {
try (OutputStream stream = bucket
.createKey(keyName, content.length(), repConfig,
.createKey(keyName, content.length, repConfig,
new HashMap<>())) {
stream.write(content.getBytes(UTF_8));
stream.write(content);
}
}

public static void createKey(OzoneBucket bucket, String keyName,
ReplicationFactor repFactor, ReplicationType repType, String content)
throws IOException {
ReplicationConfig repConfig = ReplicationConfig
.fromTypeAndFactor(repType, repFactor);
createKey(bucket, keyName, repConfig, content.getBytes(UTF_8));
}

public static void createKey(OzoneBucket bucket, String keyName,
ReplicationConfig repConfig, String content)
throws IOException {
createKey(bucket, keyName, repConfig, content.getBytes(UTF_8));
}

public static void createKey(OzoneBucket bucket, String keyName,
ReplicationFactor repFactor, ReplicationType repType,
ByteBuffer data) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.hadoop.ozone.om;

import static org.apache.hadoop.ozone.OzoneAcl.AclScope.DEFAULT;
import static org.apache.hadoop.ozone.TestDataUtil.createKey;
import static org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLIdentityType.USER;
import static org.apache.hadoop.ozone.security.acl.OzoneObj.StoreType.OZONE;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand All @@ -32,7 +33,6 @@
import org.apache.hadoop.ozone.client.OzoneBucket;
import org.apache.hadoop.ozone.client.OzoneClient;
import org.apache.hadoop.ozone.client.OzoneVolume;
import org.apache.hadoop.ozone.client.io.OzoneOutputStream;
import org.apache.hadoop.ozone.client.protocol.ClientProtocol;
import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
import org.apache.hadoop.ozone.security.acl.OzoneObj;
Expand Down Expand Up @@ -92,8 +92,8 @@ public void testBucketOwner() throws Exception {
.getVolume(VOLUME_NAME);
OzoneBucket ozoneBucket = volume.getBucket("bucket1");
//Key Create
createKey(ozoneBucket, "key1", 10, new byte[10]);
createKey(ozoneBucket, "key2", 10, new byte[10]);
createKey(ozoneBucket, "key1", new byte[10]);
createKey(ozoneBucket, "key2", new byte[10]);
//Key Delete
ozoneBucket.deleteKey("key1");
//Bucket Delete
Expand All @@ -118,7 +118,7 @@ public void testNonBucketNonVolumeOwner() throws Exception {
assertThrows(Exception.class, () -> {
OzoneVolume volume = client.getObjectStore().getVolume(VOLUME_NAME);
OzoneBucket ozoneBucket = volume.getBucket("bucket1");
createKey(ozoneBucket, "key3", 10, new byte[10]);
createKey(ozoneBucket, "key3", new byte[10]);
}, "Create key as non-volume and non-bucket owner should fail");
}
//Key Delete - should fail
Expand Down Expand Up @@ -173,8 +173,7 @@ public void testVolumeOwner() throws Exception {
try (OzoneClient client = cluster().newClient()) {
OzoneVolume volume = client.getObjectStore().getVolume(VOLUME_NAME);
OzoneBucket ozoneBucket = volume.getBucket("bucket1");
//Key Create
createKey(ozoneBucket, "key2", 10, new byte[10]);
createKey(ozoneBucket, "key2", new byte[10]);
//Key Delete
ozoneBucket.deleteKey("key2");
//List Keys
Expand Down Expand Up @@ -208,12 +207,4 @@ private static void setVolumeAcl(ObjectStore store, String volumeName,
.setResType(OzoneObj.ResourceType.VOLUME).setStoreType(OZONE).build();
assertTrue(store.setAcl(obj, OzoneAcl.parseAcls(aclString)));
}

private void createKey(OzoneBucket ozoneBucket, String key, int length,
byte[] input) throws Exception {
OzoneOutputStream ozoneOutputStream = ozoneBucket.createKey(key, length);
ozoneOutputStream.write(input);
ozoneOutputStream.write(input, 0, 10);
ozoneOutputStream.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static com.google.common.collect.Lists.newLinkedList;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_CLIENT_LIST_CACHE_SIZE;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_FS_ITERATE_BATCH_SIZE;
import static org.apache.hadoop.ozone.TestDataUtil.createKey;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.params.provider.Arguments.of;

Expand All @@ -33,6 +34,8 @@
import java.util.Optional;
import java.util.stream.Stream;
import org.apache.hadoop.hdds.client.ReplicationConfig;
import org.apache.hadoop.hdds.client.ReplicationFactor;
import org.apache.hadoop.hdds.client.ReplicationType;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.utils.IOUtils;
import org.apache.hadoop.ozone.TestDataUtil;
Expand All @@ -41,7 +44,6 @@
import org.apache.hadoop.ozone.client.OzoneClientFactory;
import org.apache.hadoop.ozone.client.OzoneKey;
import org.apache.hadoop.ozone.client.io.OzoneInputStream;
import org.apache.hadoop.ozone.client.io.OzoneOutputStream;
import org.apache.hadoop.ozone.om.helpers.BucketLayout;
import org.apache.ozone.test.NonHATests;
import org.junit.jupiter.api.AfterAll;
Expand Down Expand Up @@ -147,7 +149,7 @@ private static void buildNameSpaceTree(OzoneBucket ozoneBucket)
keys.add("a1/b3/e2/e21.tx");
keys.add("a1/b3/e3/e31.tx");

createKeys(ozoneBucket, keys);
createAndAssertKeys(ozoneBucket, keys);

ozoneBucket.createDirectory("a1/b4/");
}
Expand Down Expand Up @@ -369,27 +371,20 @@ private void checkKeyShallowList(String keyPrefix, String startKey,
assertEquals(keys, outputKeysList);
}

private static void createKeys(OzoneBucket ozoneBucket, List<String> keys)
private static void createAndAssertKeys(OzoneBucket ozoneBucket, List<String> keys)
throws Exception {
int length = 10;
byte[] input = new byte[length];
Arrays.fill(input, (byte) 96);
for (String key : keys) {
createKey(ozoneBucket, key, 10, input);
createKey(ozoneBucket, key, ReplicationFactor.THREE, ReplicationType.RATIS, input);
// Read the key with given key name.
readkey(ozoneBucket, key, length, input);
}
}

private static void createKey(OzoneBucket ozoneBucket, String key, int length,
byte[] input) throws Exception {

OzoneOutputStream ozoneOutputStream =
ozoneBucket.createKey(key, length);

ozoneOutputStream.write(input);
ozoneOutputStream.write(input, 0, 10);
ozoneOutputStream.close();

// Read the key with given key name.
private static void readkey(OzoneBucket ozoneBucket, String key, int length, byte[] input)
throws Exception {
OzoneInputStream ozoneInputStream = ozoneBucket.readKey(key);
byte[] read = new byte[length];
ozoneInputStream.read(read, 0, length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_CLIENT_LIST_CACHE_SIZE;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_FS_ITERATE_BATCH_SIZE;
import static org.apache.hadoop.ozone.TestDataUtil.createKey;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.nio.charset.StandardCharsets;
Expand All @@ -30,6 +31,8 @@
import java.util.Optional;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.hadoop.hdds.client.ReplicationConfig;
import org.apache.hadoop.hdds.client.ReplicationFactor;
import org.apache.hadoop.hdds.client.ReplicationType;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.StorageType;
import org.apache.hadoop.hdds.utils.IOUtils;
Expand All @@ -41,7 +44,6 @@
import org.apache.hadoop.ozone.client.OzoneKey;
import org.apache.hadoop.ozone.client.OzoneVolume;
import org.apache.hadoop.ozone.client.io.OzoneInputStream;
import org.apache.hadoop.ozone.client.io.OzoneOutputStream;
import org.apache.hadoop.ozone.om.helpers.BucketLayout;
import org.apache.ozone.test.NonHATests;
import org.junit.jupiter.api.AfterAll;
Expand Down Expand Up @@ -548,7 +550,7 @@ private static void buildNameSpaceTree(OzoneBucket ozoneBucket)
keys.add("/a1/b3/e2/e21.tx");
keys.add("/a1/b3/e3/e31.tx");

createKeys(ozoneBucket, keys);
createAndAssertKeys(ozoneBucket, keys);
}

private static void buildNameSpaceTree2(OzoneBucket ozoneBucket)
Expand All @@ -575,7 +577,7 @@ private static void buildNameSpaceTree2(OzoneBucket ozoneBucket)

keys.add("/dir1/dir2/dir3/d11.tx");

createKeys(ozoneBucket, keys);
createAndAssertKeys(ozoneBucket, keys);
}


Expand Down Expand Up @@ -641,33 +643,26 @@ private void checkKeyShallowList(String keyPrefix, String startKey,
checkKeyList(keyPrefix, startKey, keys, fsoBucket, true);
}

private static void createKeys(OzoneBucket ozoneBucket, List<String> keys)
private static void createAndAssertKeys(OzoneBucket ozoneBucket, List<String> keys)
throws Exception {
int length = 10;
byte[] input = new byte[length];
Arrays.fill(input, (byte) 96);
for (String key : keys) {
createKey(ozoneBucket, key, 10, input);
createKey(ozoneBucket, key, ReplicationFactor.THREE,
ReplicationType.RATIS, input);
// Read the key with given key name.
readkey(ozoneBucket, key, length, input);
}
}

private static void createKey(OzoneBucket ozoneBucket, String key, int length,
byte[] input) throws Exception {

OzoneOutputStream ozoneOutputStream =
ozoneBucket.createKey(key, length);

ozoneOutputStream.write(input);
ozoneOutputStream.write(input, 0, 10);
ozoneOutputStream.close();

// Read the key with given key name.
private static void readkey(OzoneBucket ozoneBucket, String key, int length, byte[] input)
throws Exception {
OzoneInputStream ozoneInputStream = ozoneBucket.readKey(key);
byte[] read = new byte[length];
ozoneInputStream.read(read, 0, length);
ozoneInputStream.close();

assertEquals(new String(input, StandardCharsets.UTF_8),
new String(read, StandardCharsets.UTF_8));
assertEquals(new String(input, StandardCharsets.UTF_8), new String(read, StandardCharsets.UTF_8));
}
}
Loading