Skip to content

Commit d25b649

Browse files
authored
Add more tests for zookeeper registry (#696)
* fix chinese word issue in screenshot * add test coverage for integration support chinese for integration screenshot * add some unit test * add more ui test * add await for resul showing * use internal screenshot * add png for screenshot
1 parent 3a26d7a commit d25b649

File tree

22 files changed

+620
-70
lines changed

22 files changed

+620
-70
lines changed

.codecov.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Documentation: https://docs.codecov.io/docs/codecov-yaml
2+
3+
codecov:
4+
branch: develop
5+
6+
coverage:
7+
status:
8+
project:
9+
default:
10+
branches:
11+
- develop
12+
13+
comment:
14+
layout: "reach,diff,flags,files,footer"
15+
behavior: default
16+
require_changes: no
17+
branches:
18+
- develop

.github/workflows/ci.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ jobs:
1919
run: ./mvnw clean install --batch-mode -DskipTests=false -Dcheckstyle.skip=false -Drat.skip=false -Dmaven.javadoc.skip=true
2020
- name: Upload coverage to codecov
2121
uses: codecov/codecov-action@v1
22-
22+
with:
23+
flags: unit

.github/workflows/integration.yml

+23-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,34 @@ jobs:
1212
run: cp docker/latest/** ./
1313
- name: Docker build
1414
run: docker build -t apache/dubbo-admin-integration:latest .
15+
- name: Prepare agent
16+
run: mkdir jacoco && wget https://repo1.maven.org/maven2/org/jacoco/org.jacoco.agent/0.8.6/org.jacoco.agent-0.8.6-runtime.jar -O jacoco/jacoco.jar && wget https://repo1.maven.org/maven2/org/jacoco/org.jacoco.cli/0.8.6/org.jacoco.cli-0.8.6-nodeps.jar -O jacoco/jacoco-cli.jar
1517
- name: Build provider and consumer image
1618
run: ./mvnw --batch-mode --projects dubbo-admin-test --activate-profiles build-provider package && ./mvnw --batch-mode --projects dubbo-admin-test --activate-profiles build-consumer package
1719
- name: Setup xvfb
18-
run: sudo apt-get install xvfb
20+
run: sudo apt-get install xvfb ttf-wqy-zenhei -y && fc-cache -v
1921
- name: Run integration test
2022
run: xvfb-run --server-args="-screen 0, 1024x768x24" ./mvnw --batch-mode --projects dubbo-admin-test --activate-profiles dubbo-admin-integration-test -Ddocker.showLogs=true docker:stop docker:remove verify
23+
- name: Save failure screenshots
24+
if: ${{ failure() }}
25+
uses: actions/upload-artifact@v2
26+
with:
27+
name: failure-screenshots
28+
path: dubbo-admin-test/target/screens/
2129
- uses: actions/upload-artifact@v2
2230
with:
2331
name: screenshots
24-
path: dubbo-admin-test/target/screens/
32+
path: dubbo-admin-test/target/screens/
33+
- name: Set up JDK
34+
uses: actions/setup-java@v1
35+
with:
36+
java-version: 8
37+
- name: Compile server project
38+
run: ./mvnw clean package -DskipTests=true -pl dubbo-admin-server
39+
- name: Generate report
40+
run: java -jar jacoco/jacoco-cli.jar report jacoco/jacoco.exec --classfiles dubbo-admin-server/target/classes/ --sourcefiles dubbo-admin-server/src --xml jacoco/jacoco.xml
41+
- name: Upload coverage to codecov
42+
uses: codecov/codecov-action@v1
43+
with:
44+
flags: integration
45+
directory: ./jacoco

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Dubbo Admin
22

33
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/apache/dubbo-admin/CI)
4-
[![codecov](https://codecov.io/gh/apache/dubbo-admin/branch/develop/graph/badge.svg)](https://codecov.io/gh/apache/dubbo-admin)
4+
[![codecov](https://codecov.io/gh/apache/dubbo-admin/branch/develop/graph/badge.svg)](https://codecov.io/gh/apache/dubbo-admin/branches/develop)
55
![license](https://img.shields.io/github/license/apache/dubbo-admin.svg)
66
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/apache/dubbo-admin.svg)](http://isitmaintained.com/project/apache/dubbo-admin "Average time to resolve an issue")
77
[![Percentage of issues still open](http://isitmaintained.com/badge/open/apache/dubbo-admin.svg)](http://isitmaintained.com/project/apache/dubbo-admin "Percentage of issues still open")

README_ZH.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Dubbo控制台
22

33
[![Build Status](https://travis-ci.org/apache/dubbo-admin.svg?branch=develop)](https://travis-ci.org/apache/dubbo-admin)
4-
[![codecov](https://codecov.io/gh/apache/dubbo-admin/branch/develop/graph/badge.svg)](https://codecov.io/gh/apache/dubbo-admin)
4+
[![codecov](https://codecov.io/gh/apache/dubbo-admin/branch/develop/graph/badge.svg)](https://codecov.io/gh/apache/dubbo-admin/branches/develop)
55
![license](https://img.shields.io/github/license/apache/dubbo-admin.svg)
66

77
[English version](README.md).

docker/latest/Dockerfile

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,9 @@ FROM openjdk:8-jre
2323
LABEL maintainer="[email protected]"
2424
RUN apt-get update && apt-get install -y tini
2525
COPY --from=0 /source/dubbo-admin-snapshot/dubbo-admin-distribution/target/dubbo-admin-0.3.0-SNAPSHOT.jar /app.jar
26-
ENTRYPOINT ["tini","--","java","-XX:+UnlockExperimentalVMOptions","-XX:+UseCGroupMemoryLimitForHeap","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
26+
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
27+
28+
ENV JAVA_OPTS = ""
29+
30+
ENTRYPOINT ["tini", "--", "/usr/local/bin/entrypoint.sh"]
2731
EXPOSE 8080

docker/latest/entrypoint.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
set -e
3+
4+
exec java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar

dubbo-admin-server/src/main/resources/application-test.properties

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#
1717

1818
# centers in dubbo2.7
19-
admin.registry.address=zookeeper://127.0.0.1:2183
20-
admin.config-center=zookeeper://127.0.0.1:2183
21-
admin.metadata.address=zookeeper://127.0.0.1:2183
19+
admin.registry.address=zookeeper://127.0.0.1:2181
20+
admin.config-center=zookeeper://127.0.0.1:2181
21+
admin.metadata.address=zookeeper://127.0.0.1:2181
2222
admin.check.authority=false

dubbo-admin-server/src/main/resources/application.properties

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
#
1717

1818
# centers in dubbo2.7
19-
admin.registry.address=zookeeper://127.0.0.1:2183
20-
admin.config-center=zookeeper://127.0.0.1:2183
21-
admin.metadata-report.address=zookeeper://127.0.0.1:2183
19+
admin.registry.address=zookeeper://127.0.0.1:2181
20+
admin.config-center=zookeeper://127.0.0.1:2181
21+
admin.metadata-report.address=zookeeper://127.0.0.1:2181
2222

2323
#admin.registry.address=nacos://127.0.0.1:8848
2424
#admin.config-center=nacos://127.0.0.1:8848
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.admin.utils;
18+
19+
import org.junit.Test;
20+
21+
import java.time.LocalDate;
22+
import java.time.LocalDateTime;
23+
24+
import static org.hamcrest.CoreMatchers.is;
25+
import static org.junit.Assert.assertThat;
26+
27+
public class LocalDateTimeUtilTest {
28+
@Test
29+
public void shouldGetLocalDateTime() {
30+
LocalDateTime localDateTime = LocalDateTimeUtil.formatToLDT("2020-01-02 10:11:12");
31+
32+
assertThat(localDateTime.getYear(), is(2020));
33+
assertThat(localDateTime.getMonthValue(), is(1));
34+
assertThat(localDateTime.getDayOfMonth(), is(2));
35+
36+
assertThat(localDateTime.getHour(), is(10));
37+
assertThat(localDateTime.getMinute(), is(11));
38+
assertThat(localDateTime.getSecond(), is(12));
39+
}
40+
41+
@Test
42+
public void shouldGetLocalDate() {
43+
LocalDate localDate = LocalDateTimeUtil.formatToLD("2020-01-02");
44+
45+
assertThat(localDate.getYear(), is(2020));
46+
assertThat(localDate.getMonthValue(), is(1));
47+
assertThat(localDate.getDayOfMonth(), is(2));
48+
}
49+
}

dubbo-admin-test/pom.xml

+10-3
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@
122122
</dependency>
123123

124124
<dependency>
125-
<groupId>org.seleniumhq.selenium.fluent</groupId>
126-
<artifactId>fluent-selenium</artifactId>
127-
<version>1.17</version>
125+
<groupId>org.fluentlenium</groupId>
126+
<artifactId>fluentlenium-junit</artifactId>
127+
<version>3.9.1</version>
128128
<scope>test</scope>
129129
</dependency>
130130

@@ -235,7 +235,13 @@
235235
</admin.config-center>
236236
<admin.metadata-report.address>zookeeper://zookeeper:2181
237237
</admin.metadata-report.address>
238+
<JAVA_OPTS>-javaagent:/jacoco/jacoco.jar=destfile=/jacoco/jacoco.exec</JAVA_OPTS>
238239
</env>
240+
<volumes>
241+
<bind>
242+
<volume>${project.basedir}/../jacoco:/jacoco</volume>
243+
</bind>
244+
</volumes>
239245
<links>
240246
<link>zookeeper:zookeeper</link>
241247
</links>
@@ -246,6 +252,7 @@
246252
<method>GET</method>
247253
<status>200</status>
248254
</http>
255+
<time>20000</time>
249256
</wait>
250257
</run>
251258
</image>

dubbo-admin-test/src/test/java/org/apache/dubbo/admin/BaseIT.java

+37-14
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,53 @@
1818
*/
1919
package org.apache.dubbo.admin;
2020

21-
import org.apache.commons.io.FileUtils;
22-
import org.openqa.selenium.OutputType;
23-
import org.openqa.selenium.TakesScreenshot;
21+
import io.github.bonigarcia.wdm.WebDriverManager;
22+
import org.apache.commons.lang3.StringUtils;
23+
import org.apache.dubbo.admin.pages.LoginPage;
24+
import org.fluentlenium.adapter.junit.FluentTest;
25+
import org.fluentlenium.core.annotation.Page;
26+
import org.junit.BeforeClass;
2427
import org.openqa.selenium.WebDriver;
2528
import org.slf4j.Logger;
2629
import org.slf4j.LoggerFactory;
2730

28-
import java.io.File;
29-
import java.io.IOException;
30-
31-
public class BaseIT {
31+
public class BaseIT extends FluentTest {
3232
private Logger logger = LoggerFactory.getLogger(this.getClass());
3333

34-
public void takeShot(WebDriver webDriver, String name) {
35-
TakesScreenshot scrShot = ((TakesScreenshot) webDriver);
34+
protected static WebDriver driver;
35+
protected static String BASE_URL;
36+
37+
@Page
38+
LoginPage loginPage;
39+
40+
public BaseIT() {
41+
setWebDriver("chrome");
42+
setScreenshotPath("target/screens/");
43+
setScreenshotMode(TriggerMode.AUTOMATIC_ON_FAIL);
44+
}
45+
46+
@BeforeClass
47+
public static void beforeClass() {
48+
WebDriverManager.chromedriver().setup();
3649

37-
File SrcFile = scrShot.getScreenshotAs(OutputType.FILE);
50+
BASE_URL = StringUtils.defaultString(System.getenv("BASEURL"), "http://localhost:8082");
51+
}
52+
53+
@Override
54+
public String getBaseUrl() {
55+
return BASE_URL;
56+
}
3857

39-
File DestFile = new File("target/screens/" + name + ".png");
58+
59+
public void autoLogin() {
60+
goTo(loginPage);
4061

4162
try {
42-
FileUtils.copyFile(SrcFile, DestFile);
43-
} catch (IOException e) {
44-
logger.info("#takeShot# take shot fail", e);
63+
await().untilPredicate(fluentControl -> loginPage.url().contains("login"));
64+
65+
loginPage.loginWithRoot();
66+
} catch (Exception ignore) {
67+
logger.info("already log in");
4568
}
4669
}
4770
}

dubbo-admin-test/src/test/java/org/apache/dubbo/admin/LoginIT.java

+7-40
Original file line numberDiff line numberDiff line change
@@ -18,51 +18,18 @@
1818
*/
1919
package org.apache.dubbo.admin;
2020

21-
import io.github.bonigarcia.wdm.WebDriverManager;
22-
import org.apache.commons.lang3.StringUtils;
23-
import org.junit.AfterClass;
24-
import org.junit.BeforeClass;
21+
import org.apache.dubbo.admin.pages.LoginPage;
22+
import org.fluentlenium.core.annotation.Page;
2523
import org.junit.Test;
26-
import org.openqa.selenium.By;
27-
import org.openqa.selenium.WebDriver;
28-
import org.openqa.selenium.firefox.FirefoxDriver;
29-
import org.seleniumhq.selenium.fluent.FluentWebDriver;
30-
31-
import java.util.concurrent.TimeUnit;
3224

3325
public class LoginIT extends BaseIT {
34-
private static WebDriver driver;
35-
private static FluentWebDriver fwd;
36-
private static String BASE_URL;
37-
38-
@BeforeClass
39-
public static void beforeClass() {
40-
WebDriverManager.firefoxdriver().setup();
41-
42-
driver = new FirefoxDriver();
43-
44-
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
45-
fwd = new FluentWebDriver(driver);
46-
47-
BASE_URL = StringUtils.defaultString(System.getenv("BASEURL"), "http://localhost:8082");
48-
}
49-
50-
@AfterClass
51-
public static void afterClass() {
52-
driver.quit();
53-
}
54-
26+
@Page
27+
private LoginPage loginPage;
5528

5629
@Test
57-
public void shouldOpenLogin() {
58-
driver.get(BASE_URL + "/#/login");
59-
60-
fwd.input(By.name("username")).sendKeys("root");
61-
fwd.input(By.cssSelector("input[type='password']")).sendKeys("root");
62-
63-
this.takeShot(driver, "login");
64-
30+
public void shouldLogin() {
31+
goTo(loginPage).loginWithRoot();
6532

66-
fwd.button(By.tagName("button")).click();
33+
loginPage.takeScreenshot("login.png");
6734
}
6835
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
*
3+
* Licensed to the Apache Software Foundation (ASF) under one or more
4+
* contributor license agreements. See the NOTICE file distributed with
5+
* this work for additional information regarding copyright ownership.
6+
* The ASF licenses this file to You under the Apache License, Version 2.0
7+
* (the "License"); you may not use this file except in compliance with
8+
* the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
*/
19+
package org.apache.dubbo.admin;
20+
21+
import org.apache.dubbo.admin.pages.ManagePage;
22+
import org.fluentlenium.core.annotation.Page;
23+
import org.junit.Test;
24+
25+
import static org.hamcrest.CoreMatchers.containsString;
26+
import static org.hamcrest.MatcherAssert.assertThat;
27+
28+
public class ManageIT extends BaseIT {
29+
@Page
30+
private ManagePage managePage;
31+
32+
@Test
33+
public void shouldViewConfig() {
34+
autoLogin();
35+
36+
goTo(managePage).showConfigDetailFor("global");
37+
38+
assertThat(managePage.getConfigDetail(), containsString("dubbo.registry.address"));
39+
40+
managePage.takeScreenshot("manage-config.png");
41+
}
42+
}

0 commit comments

Comments
 (0)