You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@linkis.apache.org by pe...@apache.org on 2022/10/11 07:01:34 UTC

[incubator-linkis] branch dev-1.3.1 updated: feat: error-code-client unit test (#3553)

This is an automated email from the ASF dual-hosted git repository.

peacewong pushed a commit to branch dev-1.3.1
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git


The following commit(s) were added to refs/heads/dev-1.3.1 by this push:
     new ebd11ff92 feat: error-code-client unit test (#3553)
ebd11ff92 is described below

commit ebd11ff92857258f9fa72ce1bc9ed824d60982af
Author: ruY <43...@users.noreply.github.com>
AuthorDate: Tue Oct 11 15:01:28 2022 +0800

    feat: error-code-client unit test (#3553)
    
    * feat: error-code-client unit test
---
 .../errorcode/client/ClientConfigurationTest.java  | 46 +++++++++++++++++++++
 .../client/ErrorCodeClientBuilderTest.java         | 42 +++++++++++++++++++
 .../client/LinkisErrorCodeClientTest.java          | 44 ++++++++++++++++++++
 .../client/handler/ErrorCodeHandlerTest.java       | 37 +++++++++++++++++
 .../client/handler/LinkisErrorCodeHandlerTest.java | 48 ++++++++++++++++++++++
 .../client/manager/LinkisErrorCodeManagerTest.java | 45 ++++++++++++++++++++
 .../LinkisErrorCodeSynchronizerTest.java           | 46 +++++++++++++++++++++
 .../client/action/ErrorCodeActionTest.scala        | 41 ++++++++++++++++++
 8 files changed, 349 insertions(+)

diff --git a/linkis-public-enhancements/linkis-error-code/linkis-error-code-client/src/test/java/org/apache/linkis/errorcode/client/ClientConfigurationTest.java b/linkis-public-enhancements/linkis-error-code/linkis-error-code-client/src/test/java/org/apache/linkis/errorcode/client/ClientConfigurationTest.java
new file mode 100644
index 000000000..7327e62ba
--- /dev/null
+++ b/linkis-public-enhancements/linkis-error-code/linkis-error-code-client/src/test/java/org/apache/linkis/errorcode/client/ClientConfigurationTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.linkis.errorcode.client;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+public class ClientConfigurationTest {
+
+  @Test
+  @DisplayName("commonConstTest")
+  public void commonConstTest() {
+
+    String linkisGatewayUrl = ClientConfiguration.LINKIS_GATEWAY_URL.getValue();
+    String errorCodeUrlPrefix = ClientConfiguration.ERRORCODE_URL_PREFIX.getValue();
+    String errorCodeGetUrl = ClientConfiguration.ERRORCODE_GET_URL.getValue();
+    Long defaultConnectTimeOut = ClientConfiguration.DEFAULT_CONNECT_TIME_OUT.getValue();
+    Long defaultReadTimeOut = ClientConfiguration.DEFAULT_READ_TIME_OUT.getValue();
+    String authTokenValue = ClientConfiguration.AUTH_TOKEN_VALUE.getValue();
+    Long futureTimeOut = ClientConfiguration.FUTURE_TIME_OUT.getValue();
+
+    Assertions.assertNotNull(linkisGatewayUrl);
+    Assertions.assertNotNull(errorCodeUrlPrefix);
+    Assertions.assertNotNull(errorCodeGetUrl);
+    Assertions.assertTrue(defaultConnectTimeOut.longValue() == 600000L);
+    Assertions.assertTrue(defaultReadTimeOut == 600000L);
+    Assertions.assertNotNull(authTokenValue);
+    Assertions.assertTrue(futureTimeOut.longValue() == 2000L);
+  }
+}
diff --git a/linkis-public-enhancements/linkis-error-code/linkis-error-code-client/src/test/java/org/apache/linkis/errorcode/client/ErrorCodeClientBuilderTest.java b/linkis-public-enhancements/linkis-error-code/linkis-error-code-client/src/test/java/org/apache/linkis/errorcode/client/ErrorCodeClientBuilderTest.java
new file mode 100644
index 000000000..fc75ebd48
--- /dev/null
+++ b/linkis-public-enhancements/linkis-error-code/linkis-error-code-client/src/test/java/org/apache/linkis/errorcode/client/ErrorCodeClientBuilderTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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.linkis.errorcode.client;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+public class ErrorCodeClientBuilderTest {
+
+  @Test
+  @DisplayName("buildTest")
+  public void buildTest() {
+
+    LinkisErrorCodeClient linkisErrorCodeClient = new ErrorCodeClientBuilder().build();
+    Assertions.assertNotNull(linkisErrorCodeClient);
+  }
+
+  @Test
+  @DisplayName("setVersionTest")
+  public void setVersionTest() {
+    String version = "v2";
+    LinkisErrorCodeClient linkisErrorCodeClient =
+        new ErrorCodeClientBuilder().setVersion(version).build();
+    Assertions.assertNotNull(linkisErrorCodeClient);
+  }
+}
diff --git a/linkis-public-enhancements/linkis-error-code/linkis-error-code-client/src/test/java/org/apache/linkis/errorcode/client/LinkisErrorCodeClientTest.java b/linkis-public-enhancements/linkis-error-code/linkis-error-code-client/src/test/java/org/apache/linkis/errorcode/client/LinkisErrorCodeClientTest.java
new file mode 100644
index 000000000..11896652f
--- /dev/null
+++ b/linkis-public-enhancements/linkis-error-code/linkis-error-code-client/src/test/java/org/apache/linkis/errorcode/client/LinkisErrorCodeClientTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.linkis.errorcode.client;
+
+import org.apache.linkis.errorcode.client.action.ErrorCodeGetAllAction;
+import org.apache.linkis.errorcode.common.LinkisErrorCode;
+import org.apache.linkis.httpclient.dws.DWSHttpClient;
+
+import java.util.List;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+public class LinkisErrorCodeClientTest {
+
+  @Test
+  @DisplayName("getErrorCodesFromServerTest")
+  public void getErrorCodesFromServerTest() {
+
+    // Simulated pile driving
+    DWSHttpClient dwsHttpClient = Mockito.mock(DWSHttpClient.class);
+    Mockito.when(dwsHttpClient.execute(Mockito.any(ErrorCodeGetAllAction.class))).thenReturn(null);
+    LinkisErrorCodeClient linkisErrorCodeClient = new LinkisErrorCodeClient(dwsHttpClient);
+    List<LinkisErrorCode> codes = linkisErrorCodeClient.getErrorCodesFromServer();
+    Assertions.assertTrue(codes.size() == 0);
+  }
+}
diff --git a/linkis-public-enhancements/linkis-error-code/linkis-error-code-client/src/test/java/org/apache/linkis/errorcode/client/handler/ErrorCodeHandlerTest.java b/linkis-public-enhancements/linkis-error-code/linkis-error-code-client/src/test/java/org/apache/linkis/errorcode/client/handler/ErrorCodeHandlerTest.java
new file mode 100644
index 000000000..c58a49109
--- /dev/null
+++ b/linkis-public-enhancements/linkis-error-code/linkis-error-code-client/src/test/java/org/apache/linkis/errorcode/client/handler/ErrorCodeHandlerTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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.linkis.errorcode.client.handler;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+public class ErrorCodeHandlerTest {
+
+  @Test
+  @DisplayName("constTest")
+  public void constTest() {
+    String errorCodePre = ErrorCodeHandler.ERROR_CODE_PRE;
+    String errorCodeOk = ErrorCodeHandler.ERROR_CODE_OK;
+    String errorCodeFailed = ErrorCodeHandler.ERROR_CODE_FAILED;
+
+    Assertions.assertNotNull(errorCodePre);
+    Assertions.assertNotNull(errorCodeOk);
+    Assertions.assertNotNull(errorCodeFailed);
+  }
+}
diff --git a/linkis-public-enhancements/linkis-error-code/linkis-error-code-client/src/test/java/org/apache/linkis/errorcode/client/handler/LinkisErrorCodeHandlerTest.java b/linkis-public-enhancements/linkis-error-code/linkis-error-code-client/src/test/java/org/apache/linkis/errorcode/client/handler/LinkisErrorCodeHandlerTest.java
new file mode 100644
index 000000000..cd2b9b9ac
--- /dev/null
+++ b/linkis-public-enhancements/linkis-error-code/linkis-error-code-client/src/test/java/org/apache/linkis/errorcode/client/handler/LinkisErrorCodeHandlerTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.linkis.errorcode.client.handler;
+
+import org.apache.linkis.errorcode.common.ErrorCode;
+
+import java.util.List;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+public class LinkisErrorCodeHandlerTest {
+
+  @Test
+  @DisplayName("getInstanceTest")
+  public void getInstanceTest() {
+
+    LinkisErrorCodeHandler instance = LinkisErrorCodeHandler.getInstance();
+    Assertions.assertNotNull(instance);
+  }
+
+  @Test
+  @DisplayName("handleTest")
+  public void handleTest() {
+
+    String log =
+        "60001,Session creation failed. The ide queue does not exist. Please check whether the queue settings are correct";
+    LinkisErrorCodeHandler instance = LinkisErrorCodeHandler.getInstance();
+    List<ErrorCode> errorCodes = instance.handle(log);
+    Assertions.assertNotNull(errorCodes);
+  }
+}
diff --git a/linkis-public-enhancements/linkis-error-code/linkis-error-code-client/src/test/java/org/apache/linkis/errorcode/client/manager/LinkisErrorCodeManagerTest.java b/linkis-public-enhancements/linkis-error-code/linkis-error-code-client/src/test/java/org/apache/linkis/errorcode/client/manager/LinkisErrorCodeManagerTest.java
new file mode 100644
index 000000000..096699dda
--- /dev/null
+++ b/linkis-public-enhancements/linkis-error-code/linkis-error-code-client/src/test/java/org/apache/linkis/errorcode/client/manager/LinkisErrorCodeManagerTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.linkis.errorcode.client.manager;
+
+import org.apache.linkis.errorcode.common.LinkisErrorCode;
+
+import java.util.List;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+public class LinkisErrorCodeManagerTest {
+
+  @Test
+  @DisplayName("getInstanceTest")
+  public void getInstanceTest() {
+
+    LinkisErrorCodeManager instance = LinkisErrorCodeManager.getInstance();
+    Assertions.assertNotNull(instance);
+  }
+
+  @Test
+  @DisplayName("getLinkisErrorCodesTest")
+  public void getLinkisErrorCodesTest() {
+
+    List<LinkisErrorCode> errorCodes = LinkisErrorCodeManager.getInstance().getLinkisErrorCodes();
+    Assertions.assertTrue(errorCodes.size() == 1);
+  }
+}
diff --git a/linkis-public-enhancements/linkis-error-code/linkis-error-code-client/src/test/java/org/apache/linkis/errorcode/client/synchronizer/LinkisErrorCodeSynchronizerTest.java b/linkis-public-enhancements/linkis-error-code/linkis-error-code-client/src/test/java/org/apache/linkis/errorcode/client/synchronizer/LinkisErrorCodeSynchronizerTest.java
new file mode 100644
index 000000000..eeaa5971c
--- /dev/null
+++ b/linkis-public-enhancements/linkis-error-code/linkis-error-code-client/src/test/java/org/apache/linkis/errorcode/client/synchronizer/LinkisErrorCodeSynchronizerTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.linkis.errorcode.client.synchronizer;
+
+import org.apache.linkis.errorcode.common.LinkisErrorCode;
+
+import java.util.List;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+public class LinkisErrorCodeSynchronizerTest {
+
+  @Test
+  @DisplayName("getInstanceTest")
+  public void getInstanceTest() {
+
+    LinkisErrorCodeSynchronizer instance = LinkisErrorCodeSynchronizer.getInstance();
+    Assertions.assertNotNull(instance);
+  }
+
+  @Test
+  @DisplayName("synchronizeErrorCodesTest")
+  public void synchronizeErrorCodesTest() {
+
+    List<LinkisErrorCode> errorCodes =
+        LinkisErrorCodeSynchronizer.getInstance().synchronizeErrorCodes();
+    Assertions.assertTrue(errorCodes.size() == 1);
+  }
+}
diff --git a/linkis-public-enhancements/linkis-error-code/linkis-error-code-client/src/test/scala/org/apache/linkis/errorcode/client/action/ErrorCodeActionTest.scala b/linkis-public-enhancements/linkis-error-code/linkis-error-code-client/src/test/scala/org/apache/linkis/errorcode/client/action/ErrorCodeActionTest.scala
new file mode 100644
index 000000000..331acdc19
--- /dev/null
+++ b/linkis-public-enhancements/linkis-error-code/linkis-error-code-client/src/test/scala/org/apache/linkis/errorcode/client/action/ErrorCodeActionTest.scala
@@ -0,0 +1,41 @@
+/*
+ * 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.linkis.errorcode.client.action
+
+import org.junit.jupiter.api.{Assertions, DisplayName, Test}
+
+class ErrorCodeActionTest {
+
+  @Test
+  @DisplayName("constTest")
+  def constTest(): Unit = {
+
+    val errorCodeAction = ErrorCodeGetAllAction()
+    val url = errorCodeAction.getURL
+    val user = errorCodeAction.getUser
+    val urlPrefix = errorCodeAction.urlPrefix
+    val allUrlSuffix = errorCodeAction.getAllUrlSuffix
+
+    Assertions.assertNotNull(url)
+    Assertions.assertNotNull(urlPrefix)
+    Assertions.assertNotNull(allUrlSuffix)
+    Assertions.assertEquals("hadoop", user)
+
+  }
+
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org