Skip to content

Commit

Permalink
Add e2e module (#2338)
Browse files Browse the repository at this point in the history
* Move TimeServiceTest to correct package

* Add e2e module

* Add e2e module
  • Loading branch information
terrymanu authored Oct 29, 2023
1 parent bfba7cd commit cb2c0db
Show file tree
Hide file tree
Showing 18 changed files with 283 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,3 @@

org.apache.shardingsphere.elasticjob.kernel.api.listener.fixture.TestDistributeOnceElasticJobListener
org.apache.shardingsphere.elasticjob.kernel.api.listener.fixture.TestElasticJobListener
org.apache.shardingsphere.elasticjob.kernel.integrate.listener.TestDistributeOnceElasticJobListener
org.apache.shardingsphere.elasticjob.kernel.integrate.listener.TestElasticJobListener
51 changes: 51 additions & 0 deletions test/e2e/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere.elasticjob</groupId>
<artifactId>elasticjob-test</artifactId>
<version>3.1.0-SNAPSHOT</version>
</parent>
<artifactId>elasticjob-test-e2e</artifactId>
<name>${project.artifactId}</name>

<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.shardingsphere.elasticjob</groupId>
<artifactId>elasticjob-kernel</artifactId>
<version>${project.parent.version}</version>
</dependency>

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

<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.shardingsphere.elasticjob.kernel.integrate;
package org.apache.shardingsphere.elasticjob.test.e2e;

import lombok.AccessLevel;
import lombok.Getter;
Expand All @@ -36,7 +36,7 @@
import org.junit.jupiter.api.BeforeEach;

@Getter(AccessLevel.PROTECTED)
public abstract class BaseIntegrateTest {
public abstract class BaseE2ETest {

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

Expand All @@ -55,7 +55,7 @@ public abstract class BaseIntegrateTest {

private final String jobName = System.nanoTime() + "_test_job";

protected BaseIntegrateTest(final TestType type, final ElasticJob elasticJob) {
protected BaseE2ETest(final TestType type, final ElasticJob elasticJob) {
this.elasticJob = elasticJob;
jobConfiguration = getJobConfiguration(jobName);
jobBootstrap = createJobBootstrap(type, elasticJob);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,30 @@
* limitations under the License.
*/

package org.apache.shardingsphere.elasticjob.kernel.integrate.disable;
package org.apache.shardingsphere.elasticjob.test.e2e.disable;

import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
import org.apache.shardingsphere.elasticjob.infra.env.IpUtils;
import org.apache.shardingsphere.elasticjob.kernel.internal.config.JobConfigurationPOJO;
import org.apache.shardingsphere.elasticjob.infra.yaml.YamlEngine;
import org.apache.shardingsphere.elasticjob.kernel.api.bootstrap.impl.ScheduleJobBootstrap;
import org.apache.shardingsphere.elasticjob.kernel.fixture.job.DetailedFooJob;
import org.apache.shardingsphere.elasticjob.kernel.integrate.BaseIntegrateTest;
import org.apache.shardingsphere.elasticjob.kernel.internal.config.JobConfigurationPOJO;
import org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobRegistry;
import org.apache.shardingsphere.elasticjob.kernel.internal.server.ServerStatus;
import org.apache.shardingsphere.elasticjob.test.e2e.BaseE2ETest;
import org.apache.shardingsphere.elasticjob.test.e2e.fixture.job.E2EFixtureJobImpl;
import org.awaitility.Awaitility;
import org.hamcrest.core.IsNull;

import java.util.concurrent.TimeUnit;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNull;

public abstract class DisabledJobIntegrateTest extends BaseIntegrateTest {
public abstract class DisabledJobE2ETest extends BaseE2ETest {

public DisabledJobIntegrateTest(final TestType type) {
super(type, new DetailedFooJob());
public DisabledJobE2ETest(final TestType type) {
super(type, new E2EFixtureJobImpl());
}

protected final void assertDisabledRegCenterInfo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
* limitations under the License.
*/

package org.apache.shardingsphere.elasticjob.kernel.integrate.disable;
package org.apache.shardingsphere.elasticjob.test.e2e.disable;

import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
import org.junit.jupiter.api.Test;

class OneOffDisabledJobIntegrateTest extends DisabledJobIntegrateTest {
class OneOffDisabledJobE2ETest extends DisabledJobE2ETest {

OneOffDisabledJobIntegrateTest() {
OneOffDisabledJobE2ETest() {
super(TestType.ONE_OFF);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
* limitations under the License.
*/

package org.apache.shardingsphere.elasticjob.kernel.integrate.disable;
package org.apache.shardingsphere.elasticjob.test.e2e.disable;

import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
import org.apache.shardingsphere.elasticjob.kernel.fixture.job.DetailedFooJob;
import org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobRegistry;
import org.apache.shardingsphere.elasticjob.kernel.internal.server.ServerStatus;
import org.apache.shardingsphere.elasticjob.test.e2e.fixture.job.E2EFixtureJobImpl;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.Test;

Expand All @@ -30,9 +30,9 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;

class ScheduleDisabledJobIntegrateTest extends DisabledJobIntegrateTest {
class ScheduleDisabledJobE2ETest extends DisabledJobE2ETest {

ScheduleDisabledJobIntegrateTest() {
ScheduleDisabledJobE2ETest() {
super(TestType.SCHEDULE);
}

Expand All @@ -46,7 +46,7 @@ protected JobConfiguration getJobConfiguration(final String jobName) {
void assertJobRunning() {
assertDisabledRegCenterInfo();
setJobEnable();
Awaitility.await().atMost(10L, TimeUnit.SECONDS).untilAsserted(() -> assertThat(((DetailedFooJob) getElasticJob()).isCompleted(), is(true)));
Awaitility.await().atMost(10L, TimeUnit.SECONDS).untilAsserted(() -> assertThat(((E2EFixtureJobImpl) getElasticJob()).isCompleted(), is(true)));
assertEnabledRegCenterInfo();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
* limitations under the License.
*/

package org.apache.shardingsphere.elasticjob.kernel.integrate.enable;
package org.apache.shardingsphere.elasticjob.test.e2e.enable;

import org.apache.shardingsphere.elasticjob.api.ElasticJob;
import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
import org.apache.shardingsphere.elasticjob.infra.env.IpUtils;
import org.apache.shardingsphere.elasticjob.kernel.internal.config.JobConfigurationPOJO;
import org.apache.shardingsphere.elasticjob.infra.yaml.YamlEngine;
import org.apache.shardingsphere.elasticjob.kernel.api.bootstrap.impl.ScheduleJobBootstrap;
import org.apache.shardingsphere.elasticjob.kernel.integrate.BaseIntegrateTest;
import org.apache.shardingsphere.elasticjob.test.e2e.BaseE2ETest;
import org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobRegistry;
import org.apache.shardingsphere.elasticjob.kernel.internal.server.ServerStatus;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -33,9 +33,9 @@
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public abstract class EnabledJobIntegrateTest extends BaseIntegrateTest {
public abstract class EnabledJobE2ETest extends BaseE2ETest {

protected EnabledJobIntegrateTest(final TestType type, final ElasticJob elasticJob) {
protected EnabledJobE2ETest(final TestType type, final ElasticJob elasticJob) {
super(type, elasticJob);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
* limitations under the License.
*/

package org.apache.shardingsphere.elasticjob.kernel.integrate.enable;
package org.apache.shardingsphere.elasticjob.test.e2e.enable;

import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
import org.apache.shardingsphere.elasticjob.kernel.fixture.job.DetailedFooJob;
import org.apache.shardingsphere.elasticjob.test.e2e.fixture.job.E2EFixtureJobImpl;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.Test;

Expand All @@ -28,10 +28,10 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;

class OneOffEnabledJobIntegrateTest extends EnabledJobIntegrateTest {
class OneOffEnabledJobE2ETest extends EnabledJobE2ETest {

OneOffEnabledJobIntegrateTest() {
super(TestType.ONE_OFF, new DetailedFooJob());
OneOffEnabledJobE2ETest() {
super(TestType.ONE_OFF, new E2EFixtureJobImpl());
}

@Override
Expand All @@ -42,7 +42,7 @@ protected JobConfiguration getJobConfiguration(final String jobName) {

@Test
void assertJobInit() {
Awaitility.await().atMost(1L, TimeUnit.MINUTES).untilAsserted(() -> assertThat(((DetailedFooJob) getElasticJob()).isCompleted(), is(true)));
Awaitility.await().atMost(1L, TimeUnit.MINUTES).untilAsserted(() -> assertThat(((E2EFixtureJobImpl) getElasticJob()).isCompleted(), is(true)));
assertTrue(getREGISTRY_CENTER().isExisted("/" + getJobName() + "/sharding"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
* limitations under the License.
*/

package org.apache.shardingsphere.elasticjob.kernel.integrate.enable;
package org.apache.shardingsphere.elasticjob.test.e2e.enable;

import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
import org.apache.shardingsphere.elasticjob.kernel.fixture.job.DetailedFooJob;
import org.apache.shardingsphere.elasticjob.test.e2e.fixture.job.E2EFixtureJobImpl;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.Test;

Expand All @@ -28,10 +28,10 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;

class ScheduleEnabledJobIntegrateTest extends EnabledJobIntegrateTest {
class ScheduleEnabledJobE2ETest extends EnabledJobE2ETest {

ScheduleEnabledJobIntegrateTest() {
super(TestType.SCHEDULE, new DetailedFooJob());
ScheduleEnabledJobE2ETest() {
super(TestType.SCHEDULE, new E2EFixtureJobImpl());
}

@Override
Expand All @@ -42,7 +42,7 @@ protected JobConfiguration getJobConfiguration(final String jobName) {

@Test
void assertJobInit() {
Awaitility.await().atMost(10L, TimeUnit.SECONDS).untilAsserted(() -> assertThat(((DetailedFooJob) getElasticJob()).isCompleted(), is(true)));
Awaitility.await().atMost(10L, TimeUnit.SECONDS).untilAsserted(() -> assertThat(((E2EFixtureJobImpl) getElasticJob()).isCompleted(), is(true)));
assertTrue(getREGISTRY_CENTER().isExisted("/" + getJobName() + "/sharding"));
}
}
Original file line number Diff line number Diff line change
@@ -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.shardingsphere.elasticjob.test.e2e.fixture.executor;

import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
import org.apache.shardingsphere.elasticjob.spi.param.JobRuntimeService;
import org.apache.shardingsphere.elasticjob.spi.param.ShardingContext;
import org.apache.shardingsphere.elasticjob.spi.type.ClassedJobItemExecutor;
import org.apache.shardingsphere.elasticjob.test.e2e.fixture.job.E2EFixtureJob;

public final class E2EFixtureJobExecutor implements ClassedJobItemExecutor<E2EFixtureJob> {

@Override
public void process(final E2EFixtureJob elasticJob, final JobConfiguration jobConfig, final JobRuntimeService jobRuntimeService, final ShardingContext shardingContext) {
elasticJob.foo(shardingContext);
}

@Override
public Class<E2EFixtureJob> getElasticJobClass() {
return E2EFixtureJob.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.elasticjob.test.e2e.fixture.job;

import org.apache.shardingsphere.elasticjob.api.ElasticJob;
import org.apache.shardingsphere.elasticjob.spi.param.ShardingContext;

public interface E2EFixtureJob extends ElasticJob {

/**
* Do job.
*
* @param shardingContext sharding context
*/
void foo(ShardingContext shardingContext);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.elasticjob.test.e2e.fixture.job;

import lombok.Getter;
import org.apache.shardingsphere.elasticjob.spi.param.ShardingContext;

import java.util.Collection;
import java.util.concurrent.CopyOnWriteArraySet;

public final class E2EFixtureJobImpl implements E2EFixtureJob {

private final Collection<Integer> completedJobItems = new CopyOnWriteArraySet<>();

@Getter
private volatile boolean completed;

@Override
public void foo(final ShardingContext shardingContext) {
completedJobItems.add(shardingContext.getShardingItem());
completed = completedJobItems.size() == shardingContext.getShardingTotalCount();
}
}
Loading

0 comments on commit cb2c0db

Please sign in to comment.