Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use EmbedTestingServer on lifecycle module #2329

Merged
merged 1 commit into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lifecycle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.shardingsphere.elasticjob</groupId>
<artifactId>elasticjob-test-util</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,49 @@

package org.apache.shardingsphere.elasticjob.lifecycle.api;

import org.apache.shardingsphere.elasticjob.lifecycle.AbstractEmbedZookeeperBaseTest;
import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;

class JobAPIFactoryTest extends AbstractEmbedZookeeperBaseTest {
class JobAPIFactoryTest {

private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(8181);

@BeforeAll
static void setUp() {
EMBED_TESTING_SERVER.start();
}

@Test
void assertCreateJobConfigAPI() {
assertThat(JobAPIFactory.createJobConfigurationAPI(getConnectionString(), "namespace", null), instanceOf(JobConfigurationAPI.class));
assertThat(JobAPIFactory.createJobConfigurationAPI(EMBED_TESTING_SERVER.getConnectionString(), "namespace", null), instanceOf(JobConfigurationAPI.class));
}

@Test
void assertCreateJobOperateAPI() {
assertThat(JobAPIFactory.createJobOperateAPI(getConnectionString(), "namespace", null), instanceOf(JobOperateAPI.class));
assertThat(JobAPIFactory.createJobOperateAPI(EMBED_TESTING_SERVER.getConnectionString(), "namespace", null), instanceOf(JobOperateAPI.class));
}

@Test
void assertCreateServerOperateAPI() {
assertThat(JobAPIFactory.createShardingOperateAPI(getConnectionString(), "namespace", null), instanceOf(ShardingOperateAPI.class));
assertThat(JobAPIFactory.createShardingOperateAPI(EMBED_TESTING_SERVER.getConnectionString(), "namespace", null), instanceOf(ShardingOperateAPI.class));
}

@Test
void assertCreateJobStatisticsAPI() {
assertThat(JobAPIFactory.createJobStatisticsAPI(getConnectionString(), "namespace", null), instanceOf(JobStatisticsAPI.class));
assertThat(JobAPIFactory.createJobStatisticsAPI(EMBED_TESTING_SERVER.getConnectionString(), "namespace", null), instanceOf(JobStatisticsAPI.class));
}

@Test
void assertCreateServerStatisticsAPI() {
assertThat(JobAPIFactory.createServerStatisticsAPI(getConnectionString(), "namespace", null), instanceOf(ServerStatisticsAPI.class));
assertThat(JobAPIFactory.createServerStatisticsAPI(EMBED_TESTING_SERVER.getConnectionString(), "namespace", null), instanceOf(ServerStatisticsAPI.class));
}

@Test
void assertCreateShardingStatisticsAPI() {
assertThat(JobAPIFactory.createShardingStatisticsAPI(getConnectionString(), "namespace", null), instanceOf(ShardingStatisticsAPI.class));
assertThat(JobAPIFactory.createShardingStatisticsAPI(EMBED_TESTING_SERVER.getConnectionString(), "namespace", null), instanceOf(ShardingStatisticsAPI.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@

package org.apache.shardingsphere.elasticjob.lifecycle.internal.reg;

import org.apache.shardingsphere.elasticjob.lifecycle.AbstractEmbedZookeeperBaseTest;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperConfiguration;
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter;
import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Method;
Expand All @@ -29,26 +30,33 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNull;

class RegistryCenterFactoryTest extends AbstractEmbedZookeeperBaseTest {
class RegistryCenterFactoryTest {

private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(8181);

@BeforeAll
static void setUp() {
EMBED_TESTING_SERVER.start();
}

@Test
void assertCreateCoordinatorRegistryCenterWithoutDigest() throws ReflectiveOperationException {
ZookeeperConfiguration zkConfig = getZookeeperConfiguration(RegistryCenterFactory.createCoordinatorRegistryCenter(getConnectionString(), "namespace", null));
ZookeeperConfiguration zkConfig = getZookeeperConfiguration(RegistryCenterFactory.createCoordinatorRegistryCenter(EMBED_TESTING_SERVER.getConnectionString(), "namespace", null));
assertThat(zkConfig.getNamespace(), is("namespace"));
assertNull(zkConfig.getDigest());
}

@Test
void assertCreateCoordinatorRegistryCenterWithDigest() throws ReflectiveOperationException {
ZookeeperConfiguration zkConfig = getZookeeperConfiguration(RegistryCenterFactory.createCoordinatorRegistryCenter(getConnectionString(), "namespace", "digest"));
ZookeeperConfiguration zkConfig = getZookeeperConfiguration(RegistryCenterFactory.createCoordinatorRegistryCenter(EMBED_TESTING_SERVER.getConnectionString(), "namespace", "digest"));
assertThat(zkConfig.getNamespace(), is("namespace"));
assertThat(zkConfig.getDigest(), is("digest"));
}

@Test
void assertCreateCoordinatorRegistryCenterFromCache() throws ReflectiveOperationException {
RegistryCenterFactory.createCoordinatorRegistryCenter(getConnectionString(), "otherNamespace", null);
ZookeeperConfiguration zkConfig = getZookeeperConfiguration(RegistryCenterFactory.createCoordinatorRegistryCenter(getConnectionString(), "otherNamespace", null));
RegistryCenterFactory.createCoordinatorRegistryCenter(EMBED_TESTING_SERVER.getConnectionString(), "otherNamespace", null);
ZookeeperConfiguration zkConfig = getZookeeperConfiguration(RegistryCenterFactory.createCoordinatorRegistryCenter(EMBED_TESTING_SERVER.getConnectionString(), "otherNamespace", null));
assertThat(zkConfig.getNamespace(), is("otherNamespace"));
assertNull(zkConfig.getDigest());
}
Expand Down