You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/04/21 09:58:53 UTC

[GitHub] [shardingsphere] sandynz commented on a diff in pull request #16985: Scaling IT test add local environment

sandynz commented on code in PR #16985:
URL: https://github.com/apache/shardingsphere/pull/16985#discussion_r854991798


##########
shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/cases/BaseITCase.java:
##########
@@ -17,45 +17,70 @@
 
 package org.apache.shardingsphere.integration.data.pipline.cases;
 
+import com.google.common.base.Joiner;
 import lombok.AccessLevel;
 import lombok.Getter;
+import lombok.SneakyThrows;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.integration.data.pipline.container.ComposedContainer;
+import org.apache.shardingsphere.integration.data.pipline.container.compose.BaseComposedContainer;
+import org.apache.shardingsphere.integration.data.pipline.container.compose.DockerComposedContainer;
+import org.apache.shardingsphere.integration.data.pipline.container.compose.LocalComposedContainer;
+import org.apache.shardingsphere.integration.data.pipline.env.IntegrationTestEnvironment;
 import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
 import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
 import org.apache.shardingsphere.mode.repository.cluster.zookeeper.CuratorZookeeperRepository;
-import org.apache.shardingsphere.test.integration.framework.container.atomic.governance.GovernanceContainer;
 import org.junit.Before;
 
-import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
 import java.util.List;
 import java.util.Properties;
 
 @Getter(AccessLevel.PROTECTED)
 public abstract class BaseITCase {
     
-    private DataSource targetDataSource;
-    
     @Getter(AccessLevel.NONE)
-    private final ComposedContainer composedContainer;
-    
-    private String databaseNetworkAlias;
+    private final BaseComposedContainer composedContainer;
     
     private ClusterPersistRepository clusterPersistRepository;
     
     public BaseITCase(final DatabaseType databaseType) {
-        composedContainer = new ComposedContainer(databaseType);
+        if (StringUtils.equalsIgnoreCase(IntegrationTestEnvironment.getInstance().getItEnvType(), "docker")) {
+            composedContainer = new DockerComposedContainer(databaseType);
+        } else {
+            composedContainer = new LocalComposedContainer(databaseType);
+        }

Review Comment:
   Could we add an enum to represent "docker" and "local" etc, it's easier to do equality judgement.



##########
shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/cases/dataset/CommonSQLCommand.java:
##########
@@ -0,0 +1,43 @@
+/*
+ * 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.shardingsphere.integration.data.pipline.cases.dataset;
+
+import lombok.Data;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@Data
+@XmlRootElement(name = "command")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class CommonSQLCommand {

Review Comment:
   Class could be `final`.



##########
shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/container/proxy/ShardingSphereProxyLocalContainer.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.shardingsphere.integration.data.pipline.container.proxy;
+
+import lombok.Getter;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.proxy.backend.config.ProxyConfigurationLoader;
+import org.apache.shardingsphere.proxy.backend.config.YamlProxyConfiguration;
+import org.apache.shardingsphere.proxy.frontend.ShardingSphereProxy;
+import org.apache.shardingsphere.proxy.initializer.BootstrapInitializer;
+import org.apache.shardingsphere.test.integration.env.DataSourceEnvironment;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.concurrent.TimeUnit;
+
+@Slf4j
+@Getter
+public class ShardingSphereProxyLocalContainer {
+    
+    private final String serverList;
+    
+    private final DatabaseType databaseType;
+    
+    private volatile boolean started;
+    
+    @SneakyThrows
+    public ShardingSphereProxyLocalContainer(final String serverList, final DatabaseType databaseType) {
+        this.serverList = serverList;
+        this.databaseType = databaseType;
+    }
+    
+    /**
+     * Wait proxy started.
+     *
+     * @param databaseType database type
+     */
+    @SneakyThrows
+    public void waitProxyStarted(final DatabaseType databaseType) {
+        int retry = 0;
+        int maxRetry = 60;
+        while (retry < maxRetry) {
+            try (Connection connection = DriverManager.getConnection(DataSourceEnvironment.getURL(databaseType, "localhost", 3307, ""), "root", "root")) {
+                log.info("Container ready");
+                started = true;
+                return;
+                // CHECKSTYLE:OFF
+            } catch (final Exception ignored) {
+                // CHECKSTYLE:ON
+            }
+            retry++;
+            TimeUnit.SECONDS.sleep(1);
+        }
+        throw new RuntimeException("Proxy not started");
+    }
+    
+    /**
+     * Start proxy.
+     */
+    @SneakyThrows
+    public synchronized void start() {
+        if (started) {

Review Comment:
   Could we put `synchronized` in `start()` method but not on method signature, though there's no high concurrency here.



##########
shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/container/proxy/ShardingSphereProxyLocalContainer.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.shardingsphere.integration.data.pipline.container.proxy;
+
+import lombok.Getter;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.proxy.backend.config.ProxyConfigurationLoader;
+import org.apache.shardingsphere.proxy.backend.config.YamlProxyConfiguration;
+import org.apache.shardingsphere.proxy.frontend.ShardingSphereProxy;
+import org.apache.shardingsphere.proxy.initializer.BootstrapInitializer;
+import org.apache.shardingsphere.test.integration.env.DataSourceEnvironment;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.concurrent.TimeUnit;
+
+@Slf4j
+@Getter
+public class ShardingSphereProxyLocalContainer {
+    
+    private final String serverList;
+    
+    private final DatabaseType databaseType;
+    
+    private volatile boolean started;
+    
+    @SneakyThrows
+    public ShardingSphereProxyLocalContainer(final String serverList, final DatabaseType databaseType) {
+        this.serverList = serverList;
+        this.databaseType = databaseType;
+    }
+    
+    /**
+     * Wait proxy started.
+     *
+     * @param databaseType database type
+     */
+    @SneakyThrows
+    public void waitProxyStarted(final DatabaseType databaseType) {
+        int retry = 0;
+        int maxRetry = 60;
+        while (retry < maxRetry) {

Review Comment:
   Could we use for loop for less code.



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org