Skip to content

Commit

Permalink
Refactor : refactor the sleep usage with awaitility (#23910)
Browse files Browse the repository at this point in the history
* Refactor : refactor the sleep usage with awaitility

* Refactor : refactor the useless timeout

* Refactor : remove all sleep usage from agent E2E
  • Loading branch information
taojintianxia authored Feb 1, 2023
1 parent 2f1a10f commit 3e275a6
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 124 deletions.
26 changes: 18 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
<mockito.version>4.8.0</mockito.version>

<protobuf-java.version>3.19.6</protobuf-java.version>
<awaitility.version>4.2.0</awaitility.version>

<!-- Plugin versions -->
<apache-rat-plugin.version>0.15</apache-rat-plugin.version>
Expand Down Expand Up @@ -572,6 +573,13 @@
<artifactId>caffeine</artifactId>
<version>${caffeine.version}</version>
</dependency>

<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>${awaitility.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -663,7 +671,7 @@
<configuration>
<trimStackTrace>false</trimStackTrace>
<excludes>
<exclude />
<exclude/>
</excludes>
</configuration>
</plugin>
Expand Down Expand Up @@ -705,7 +713,7 @@
</filter>
</filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
</configuration>
</plugin>
Expand All @@ -732,7 +740,7 @@
</goals>
</pluginExecutionFilter>
<action>
<ignore />
<ignore/>
</action>
</pluginExecution>
<pluginExecution>
Expand All @@ -744,7 +752,7 @@
</goals>
</pluginExecutionFilter>
<action>
<ignore />
<ignore/>
</action>
</pluginExecution>
</pluginExecutions>
Expand Down Expand Up @@ -988,10 +996,12 @@
<replace>
<name>Leading blank line</name>
<search>--&gt;
&lt;project</search>
&lt;project
</search>
<replacement>--&gt;

&lt;project</replacement>

&lt;project
</replacement>
</replace>
</pom>
</configuration>
Expand Down Expand Up @@ -1204,7 +1214,7 @@
<configuration>
<trimStackTrace>false</trimStackTrace>
<excludes>
<exclude />
<exclude/>
</excludes>
<argLine>--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED</argLine>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import com.zaxxer.hikari.HikariDataSource;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.awaitility.Awaitility;
import org.awaitility.Durations;

import javax.sql.DataSource;
import java.sql.Connection;
Expand Down Expand Up @@ -63,14 +65,7 @@ private static DataSource createHikariCP(final Properties props) {

private void waitForEnvironmentReady(final Properties props) {
log.info("Proxy with agent environment initializing ...");
int retryCount = 0;
while (!isProxyReady(props) && retryCount < Integer.parseInt(props.getProperty("proxy.retry", "30"))) {
try {
Thread.sleep(Long.parseLong(props.getProperty("proxy.waitMs", "1000")));
} catch (final InterruptedException ignore) {
}
retryCount++;
}
Awaitility.await().atMost(Durations.ONE_MINUTE).until(() -> isProxyReady(props));
}

private boolean isProxyReady(final Properties props) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ public final class MetricsPluginE2EIT extends BasePluginE2EIT {
public void assertProxyWithAgent() throws IOException {
super.assertProxyWithAgent();
Properties props = E2ETestEnvironment.getInstance().getProps();
try {
Thread.sleep(Long.parseLong(props.getProperty("prometheus.waitMs", "60000")));
} catch (final InterruptedException ignore) {
}
String metaDataURL = props.getProperty("prometheus.metadata.url");
String queryURL = props.getProperty("prometheus.query.url");
Collection<String> metricsNames = buildMetricsNames();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ it.env.value=metrics
proxy.url=jdbc:mysql://127.0.0.1:43070/agent-metrics-db?serverTimezone=UTC&useSSL=false&useLocalSessionState=true&characterEncoding=utf-8
proxy.username=root
proxy.password=root
proxy.retry=100
proxy.waitMs=1000

prometheus.waitMs=60000
prometheus.metadata.url=http://127.0.0.1:19090/api/v1/metadata?metric=
prometheus.query.url=http://127.0.0.1:19090/api/v1/query?query=
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ public void before() {
@Test
public void assertProxyWithAgent() {
super.assertProxyWithAgent();
try {
Thread.sleep(Long.parseLong(props.getProperty("jaeger.waitMs", "60000")));
} catch (final InterruptedException ignore) {
}
assertTraces();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ it.env.value=jaeger
proxy.url=jdbc:mysql://127.0.0.1:43071/agent-tracing-jaeger-db?serverTimezone=UTC&useSSL=false&useLocalSessionState=true&characterEncoding=utf-8
proxy.username=root
proxy.password=root
proxy.retry=100
proxy.waitMs=1000

jaeger.waitMs=60000
jaeger.url=http://127.0.0.1:26686/api/
jaeger.servername=shardingsphere
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ public final class OpenTelemetryPluginE2EIT extends BasePluginE2EIT {
public void assertProxyWithAgent() throws IOException {
super.assertProxyWithAgent();
Properties props = E2ETestEnvironment.getInstance().getProps();
try {
Thread.sleep(Long.parseLong(props.getProperty("opentelemetry.waitMs", "60000")));
} catch (final InterruptedException ignore) {
}
String url = props.getProperty("opentelemetry.zipkin.url") + props.getProperty("opentelemetry.servername");
Collection<TracingResult> traces = new LinkedList<>();
Gson gson = new Gson();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ it.env.value=opentelemetry
proxy.url=jdbc:mysql://127.0.0.1:43071/agent-tracing-opentelemetry-db?serverTimezone=UTC&useSSL=false&useLocalSessionState=true&characterEncoding=utf-8
proxy.username=root
proxy.password=root
proxy.retry=60
proxy.waitMs=1000

opentelemetry.waitMs=60000
opentelemetry.zipkin.url=http://127.0.0.1:19411/api/v2/traces?serviceName=
opentelemetry.servername=shardingsphere

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ public void before() {
@SneakyThrows(IOException.class)
public void assertProxyWithAgent() {
super.assertProxyWithAgent();
try {
// TODO this needs to refactor, replace sleep with polling.
Thread.sleep(Long.parseLong(props.getProperty("zipkin.waitMs", "60000")));
} catch (final InterruptedException ignore) {
}
assertSpans();
assertTraces();
assertTraceContent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ it.env.value=zipkin
proxy.url=jdbc:mysql://127.0.0.1:43071/agent-tracing-zipkin-db?serverTimezone=UTC&useSSL=false&useLocalSessionState=true&characterEncoding=utf-8
proxy.username=root
proxy.password=root
proxy.retry=100
proxy.waitMs=1000

zipkin.waitMs=60000
zipkin.url=http://127.0.0.1:19411/api/v2/
zipkin.servername=shardingsphere
7 changes: 7 additions & 0 deletions test/e2e/agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
<module>plugins</module>
</modules>

<dependencies>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
</dependency>
</dependencies>

<properties>
<maven.deploy.skip>true</maven.deploy.skip>
<docker.distribution.name>apache-shardingsphere-${project.version}-shardingsphere-proxy-bin</docker.distribution.name>
Expand Down

0 comments on commit 3e275a6

Please sign in to comment.