anuragp010 commented on code in PR #12080:
URL: https://github.com/apache/ozone/pull/12080#discussion_r4662231696
##########
hadoop-ozone/client/src/test/java/org/apache/hadoop/ozone/client/rpc/TestRpcClient.java:
##########
@@ -810,6 +811,119 @@ public OMResponse submitRequest(OMRequest request) throws
IOException {
}
}
+ /**
+ * A storage policy field is sent only to an OM that supports it, and a
request without one is never rejected.
+ */
+ @ParameterizedTest
+ @EnumSource(value = OzoneManagerVersion.class, mode =
EnumSource.Mode.EXCLUDE, names = "UNKNOWN_VERSION")
+ public void
testCreateBucketWithStoragePolicyRequiresSupportedOmVersion(OzoneManagerVersion
version)
+ throws IOException {
+ List<BucketInfo> requests = new ArrayList<>();
+ OmTransport transport = new MockOmTransport() {
+ @Override
+ public OMResponse submitRequest(OMRequest request) throws IOException {
+ if (request.getCmdType() == Type.ServiceList) {
+ return
OMResponse.newBuilder().setCmdType(Type.ServiceList).setStatus(Status.OK).setSuccess(true)
+
.setServiceListResponse(ServiceListResponse.newBuilder().addServiceInfo(om(version).getProtobuf()))
+ .build();
+ }
+ if (request.getCmdType() == Type.CreateBucket) {
+ requests.add(request.getCreateBucketRequest().getBucketInfo());
+ throw new IOException("captured");
+ }
+ return super.submitRequest(request);
+ }
+ };
+ RpcClient client = createRpcClient(transport);
+ try {
+ IOException withoutPolicyError = assertThrows(IOException.class, () ->
client.createBucket(
+ "vol", "bucket", BucketArgs.newBuilder().build()));
+ IOException withPolicyError = assertThrows(IOException.class, () ->
client.createBucket(
+ "vol", "bucket",
BucketArgs.newBuilder().setStoragePolicy(OzoneStoragePolicy.COLD).build()));
+ IOException withFallbackError = assertThrows(IOException.class, () ->
client.createBucket(
+ "vol", "bucket",
BucketArgs.newBuilder().setAllowFallbackStoragePolicy(false).build()));
+
+ assertThat(withoutPolicyError).hasMessage("captured");
+ assertThat(requests.get(0).hasStoragePolicy()).isFalse();
+ assertThat(requests.get(0).hasAllowFallbackStoragePolicy()).isFalse();
+ if (OzoneManagerVersion.STORAGE_POLICY_SUPPORT.isSupportedBy(version)) {
+ assertThat(withPolicyError).hasMessage("captured");
+ assertThat(withFallbackError).hasMessage("captured");
+ assertThat(requests).hasSize(3);
+
assertThat(requests.get(1).getStoragePolicy()).isEqualTo(OzoneStoragePolicy.toProto(OzoneStoragePolicy.COLD));
+ assertThat(requests.get(2).hasAllowFallbackStoragePolicy()).isTrue();
+ assertThat(requests.get(2).getAllowFallbackStoragePolicy()).isFalse();
+ } else {
+ assertThat(withPolicyError).hasMessage("OzoneManager does not support
storage policy");
+ assertThat(withFallbackError).hasMessage("OzoneManager does not
support storage policy");
+ assertThat(requests).hasSize(1);
+ }
+ } finally {
+ client.close();
+ }
+ }
+
+ /**
+ * Setting a storage policy needs an OM that supports it, whatever the
arguments are. This includes
+ * arguments that carry no storage policy field, since the method is a
public storage policy API.
+ */
+ @ParameterizedTest
+ @EnumSource(value = OzoneManagerVersion.class, mode =
EnumSource.Mode.EXCLUDE, names = "UNKNOWN_VERSION")
+ public void
testSetBucketStoragePolicyRequiresSupportedOmVersion(OzoneManagerVersion
version)
+ throws IOException {
+ List<OzoneManagerProtocolProtos.BucketArgs> requests = new ArrayList<>();
+ OmTransport transport = new MockOmTransport() {
+ @Override
+ public OMResponse submitRequest(OMRequest request) throws IOException {
+ if (request.getCmdType() == Type.ServiceList) {
+ return
OMResponse.newBuilder().setCmdType(Type.ServiceList).setStatus(Status.OK).setSuccess(true)
+
.setServiceListResponse(ServiceListResponse.newBuilder().addServiceInfo(om(version).getProtobuf()))
+ .build();
Review Comment:
Thanks @devmadhuu for the review and pointing this out. Yes, a helper would
be better . Have added the same. This would helper would be useful to reduce
code duplication in the future JIRAs of storage policy too !
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]