You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by dz...@apache.org on 2022/05/12 04:48:26 UTC
[drill] branch master updated: DRILL-8218: Add unit tests for StorageResource REST endpoints (#2541)
This is an automated email from the ASF dual-hosted git repository.
dzamo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/drill.git
The following commit(s) were added to refs/heads/master by this push:
new 6b10f87192 DRILL-8218: Add unit tests for StorageResource REST endpoints (#2541)
6b10f87192 is described below
commit 6b10f8719258be12fc0defe8d92a63d3fbd3fbbf
Author: James Turton <91...@users.noreply.github.com>
AuthorDate: Thu May 12 06:48:20 2022 +0200
DRILL-8218: Add unit tests for StorageResource REST endpoints (#2541)
---
.../exec/server/rest/StorageResourcesTest.java | 85 ++++++++++++++++++++++
.../org/apache/drill/test/RestClientFixture.java | 26 +++++++
2 files changed, 111 insertions(+)
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/StorageResourcesTest.java b/exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/StorageResourcesTest.java
new file mode 100644
index 0000000000..f0420df4b9
--- /dev/null
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/StorageResourcesTest.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.server.rest;
+
+import org.apache.drill.common.logical.StoragePluginConfig;
+import org.apache.drill.exec.ExecConstants;
+import org.apache.drill.exec.store.mock.MockStorageEngineConfig;
+import org.apache.drill.test.ClusterFixture;
+import org.apache.drill.test.ClusterFixtureBuilder;
+import org.apache.drill.test.ClusterTest;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class StorageResourcesTest extends ClusterTest {
+ @BeforeClass
+ public static void setUp() throws Exception {
+ ClusterFixtureBuilder builder = ClusterFixture.builder(dirTestWatcher)
+ .configProperty(ExecConstants.HTTP_ENABLE, true)
+ .configProperty(ExecConstants.HTTP_PORT_HUNT, true);
+
+ startCluster(builder);
+ }
+
+ @AfterClass
+ public static void cleanUp() throws Exception {
+ cluster.close();
+ }
+
+ @Test
+ public void testCreateStorageConfig() throws Exception {
+ try {
+ PluginConfigWrapper pcw = new PluginConfigWrapper(MockStorageEngineConfig.NAME, MockStorageEngineConfig.INSTANCE);
+ cluster.restClientFixture().postStorageConfig(pcw);
+ StoragePluginConfig config_server = cluster.storageRegistry().getDefinedConfig(MockStorageEngineConfig.NAME);
+ Assert.assertEquals(MockStorageEngineConfig.INSTANCE, config_server);
+ Assert.assertTrue(config_server.isEnabled());
+ } finally {
+ cluster.storageRegistry().remove(MockStorageEngineConfig.NAME);
+ }
+ }
+
+ @Test
+ public void testEnabledToggle() throws Exception {
+ try {
+ PluginConfigWrapper pcw = new PluginConfigWrapper(MockStorageEngineConfig.NAME, MockStorageEngineConfig.INSTANCE);
+ cluster.restClientFixture().postStorageConfig(pcw);
+ cluster.restClientFixture().toggleEnabled(MockStorageEngineConfig.NAME, false);
+ StoragePluginConfig config_server = cluster.storageRegistry().getStoredConfig(MockStorageEngineConfig.NAME);
+ Assert.assertEquals(pcw.getConfig(), config_server);
+ Assert.assertFalse(config_server.isEnabled());
+ } finally {
+ cluster.storageRegistry().remove(MockStorageEngineConfig.NAME);
+ }
+ }
+
+ @Test
+ public void testDeleteStorageConfig() throws Exception {
+ try {
+ PluginConfigWrapper pcw = new PluginConfigWrapper(MockStorageEngineConfig.NAME, MockStorageEngineConfig.INSTANCE);
+ cluster.restClientFixture().postStorageConfig(pcw);
+ cluster.restClientFixture().deleteStorageConfig(MockStorageEngineConfig.NAME);
+ StoragePluginConfig config_server = cluster.storageRegistry().getStoredConfig(MockStorageEngineConfig.NAME);
+ Assert.assertNull(config_server);
+ } finally {
+ cluster.storageRegistry().remove(MockStorageEngineConfig.NAME);
+ }
+ }
+}
diff --git a/exec/java-exec/src/test/java/org/apache/drill/test/RestClientFixture.java b/exec/java-exec/src/test/java/org/apache/drill/test/RestClientFixture.java
index b0cbe1d8d5..2c5e4a87c4 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/test/RestClientFixture.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/test/RestClientFixture.java
@@ -18,6 +18,7 @@
package org.apache.drill.test;
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
+import org.apache.drill.exec.server.rest.PluginConfigWrapper;
import org.apache.drill.shaded.guava.com.google.common.base.Preconditions;
import org.apache.drill.exec.server.rest.StatusResources;
import org.glassfish.jersey.client.ClientConfig;
@@ -25,6 +26,7 @@ import org.glassfish.jersey.client.JerseyClientBuilder;
import javax.annotation.Nullable;
import javax.ws.rs.client.Client;
+import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
@@ -120,6 +122,30 @@ public class RestClientFixture implements AutoCloseable {
return null;
}
+ public PluginConfigWrapper getStorageConfig(String name) {
+ return baseTarget.path(String.format("/storage/%s.json", name))
+ .request(MediaType.APPLICATION_JSON)
+ .get(new GenericType<PluginConfigWrapper>() {});
+ }
+
+ public void postStorageConfig(PluginConfigWrapper pcw) {
+ baseTarget.path(String.format("/storage/%s.json", pcw.getName()))
+ .request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(pcw, MediaType.APPLICATION_JSON));
+ }
+
+ public void toggleEnabled(String name, boolean b) {
+ baseTarget.path(String.format("/storage/%s/enable/%b", name, b))
+ .request(MediaType.APPLICATION_JSON)
+ .post(Entity.json(""));
+ }
+
+ public void deleteStorageConfig(String name) {
+ baseTarget.path(String.format("/storage/%s.json", name))
+ .request(MediaType.APPLICATION_JSON)
+ .delete();
+ }
+
@Override
public void close() throws Exception {
client.close();