Skip to content

Commit

Permalink
refactor test case for spring namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Feb 5, 2016
1 parent 231d06a commit d9d56ff
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@

import com.dangdang.ddframe.job.exception.JobException;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

/**
* 基于Spring AOP获取目标对象.
*
* @author caohao
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class AopTargetUtils {

private AopTargetUtils() {
}

/**
* 获取目标对象.
*
Expand Down Expand Up @@ -64,7 +65,6 @@ private static Object getProxyTargetObject(final Object proxy, final String prox
} catch (final IllegalAccessException ex) {
throw new JobException(ex);
}

}

private static Object getProxyTargetObjectForCglibAndSpring4(final Object proxy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@

import com.dangdang.ddframe.job.spring.WithNamespaceTest;
import com.dangdang.ddframe.job.spring.WithoutNamespaceTest;
import com.dangdang.ddframe.job.spring.failure.ClassNotElasticJobTest;
import com.dangdang.ddframe.job.spring.failure.ClassNotFoundTest;

@RunWith(Suite.class)
@SuiteClasses({
WithNamespaceTest.class,
WithoutNamespaceTest.class,
ClassNotFoundTest.class,
ClassNotElasticJobTest.class
WithoutNamespaceTest.class
})
public class AllSpringJobTests {
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,15 @@
import com.dangdang.ddframe.test.AbstractZookeeperJUnit4SpringContextTests;
import com.dangdang.ddframe.test.WaitingUtils;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public abstract class AbstractJobSpringIntegrateTest extends AbstractZookeeperJUnit4SpringContextTests {

private final String simpleJobName;

private final String throughputDataFlowJobName;

@Resource
private CoordinatorRegistryCenter regCenter;

Expand All @@ -45,14 +52,13 @@ public abstract class AbstractJobSpringIntegrateTest extends AbstractZookeeperJU
public void reset() {
SimpleElasticJob.reset();
ThroughputDataFlowElasticJob.reset();
ProcessCountStatistics.reset("testJob");
ProcessCountStatistics.reset(throughputDataFlowJobName);
}

@After
public void tearDown() {
JobRegistry.getInstance().getJobScheduler("simpleElasticJob").shutdown();
JobRegistry.getInstance().getJobScheduler("throughputDataFlowElasticJob").shutdown();
WaitingUtils.waitingLongTime();
JobRegistry.getInstance().getJobScheduler(simpleJobName).shutdown();
JobRegistry.getInstance().getJobScheduler(throughputDataFlowJobName).shutdown();
}

@Test
Expand All @@ -67,14 +73,14 @@ private void assertSimpleElasticJobBean() {
}
assertTrue(SimpleElasticJob.isCompleted());
assertThat(SimpleElasticJob.getJobValue(), is("simple"));
assertTrue(regCenter.isExisted("/simpleElasticJob/execution"));
assertTrue(regCenter.isExisted("/" + simpleJobName + "/execution"));
}

private void assertThroughputDataFlowElasticJobBean() {
while (!ThroughputDataFlowElasticJob.isCompleted()) {
WaitingUtils.waitingShortTime();
}
assertTrue(ThroughputDataFlowElasticJob.isCompleted());
assertTrue(regCenter.isExisted("/throughputDataFlowElasticJob/execution"));
assertTrue(regCenter.isExisted("/" + throughputDataFlowJobName + "/execution"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@
import org.springframework.test.context.ContextConfiguration;

@ContextConfiguration(locations = "classpath:META-INF/job/withNamespace.xml")
public final class WithNamespaceTest extends AbstractJobSpringIntegrateTest { }
public final class WithNamespaceTest extends AbstractJobSpringIntegrateTest {

public WithNamespaceTest() {
super("simpleElasticJob_namespace", "throughputDataFlowElasticJob_namespace");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@
import org.springframework.test.context.ContextConfiguration;

@ContextConfiguration(locations = "classpath:META-INF/job/withoutNamespace.xml")
public final class WithoutNamespaceTest extends AbstractJobSpringIntegrateTest { }
public final class WithoutNamespaceTest extends AbstractJobSpringIntegrateTest {

public WithoutNamespaceTest() {
super("simpleElasticJob_no_namespace", "throughputDataFlowElasticJob_no_namespace");
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<context:property-placeholder location="classpath:conf/job/conf.properties" />
<reg:zookeeper id="regCenter" serverLists="localhost:3181" namespace="dd-job" baseSleepTimeMilliseconds="1000" maxSleepTimeMilliseconds="3000" maxRetries="3" />

<job:bean id="simpleElasticJob" class="com.dangdang.ddframe.job.fixture.SimpleElasticJob" regCenter="regCenter" cron="${simpleElasticJob.cron}" shardingTotalCount="${simpleElasticJob.shardingTotalCount}" shardingItemParameters="${simpleElasticJob.shardingItemParameters}" disabled="${simpleElasticJob.disabled}" overwrite="${simpleElasticJob.overwrite}" />
<job:bean id="throughputDataFlowElasticJob" class="com.dangdang.ddframe.job.fixture.ThroughputDataFlowElasticJob" regCenter="regCenter" cron="0/1 * * * * ?" shardingTotalCount="3" shardingItemParameters="0=A,1=B,2=C" processCountIntervalSeconds="10" concurrentDataProcessThreadCount="3" fetchDataCount="100" description="中文描述" overwrite="true" />
<job:bean id="simpleElasticJob_namespace" class="com.dangdang.ddframe.job.fixture.SimpleElasticJob" regCenter="regCenter" cron="${simpleElasticJob.cron}" shardingTotalCount="${simpleElasticJob.shardingTotalCount}" shardingItemParameters="${simpleElasticJob.shardingItemParameters}" disabled="${simpleElasticJob.disabled}" overwrite="${simpleElasticJob.overwrite}" />
<job:bean id="throughputDataFlowElasticJob_namespace" class="com.dangdang.ddframe.job.fixture.ThroughputDataFlowElasticJob" regCenter="regCenter" cron="0/1 * * * * ?" shardingTotalCount="3" shardingItemParameters="0=A,1=B,2=C" processCountIntervalSeconds="10" concurrentDataProcessThreadCount="3" fetchDataCount="100" description="中文描述" overwrite="true" />

<bean id="simpleElasticJobBean" class="com.dangdang.ddframe.job.fixture.SimpleElasticJob">
<property name="springValue" value="simple" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
</constructor-arg>
</bean>

<bean id="simpleElasticJob" class="com.dangdang.ddframe.job.spring.schedule.SpringJobScheduler" init-method="init">
<bean id="simpleElasticJob_no_namespace" class="com.dangdang.ddframe.job.spring.schedule.SpringJobScheduler" init-method="init">
<constructor-arg ref="regCenter"></constructor-arg>
<constructor-arg>
<bean class="com.dangdang.ddframe.job.api.JobConfiguration">
<constructor-arg name="jobName" value="simpleElasticJob" />
<constructor-arg name="jobName" value="simpleElasticJob_no_namespace" />
<constructor-arg name="jobClass" value="com.dangdang.ddframe.job.fixture.SimpleElasticJob" />
<constructor-arg name="shardingTotalCount" value="${simpleElasticJob.shardingTotalCount}" />
<constructor-arg name="cron" value="0/1 * * * * ?" />
Expand All @@ -36,11 +36,11 @@
</constructor-arg>
</bean>

<bean id="throughputDataFlowElasticJob" class="com.dangdang.ddframe.job.spring.schedule.SpringJobScheduler" init-method="init">
<bean id="throughputDataFlowElasticJob_no_namespace" class="com.dangdang.ddframe.job.spring.schedule.SpringJobScheduler" init-method="init">
<constructor-arg ref="regCenter"></constructor-arg>
<constructor-arg>
<bean class="com.dangdang.ddframe.job.api.JobConfiguration">
<constructor-arg name="jobName" value="throughputDataFlowElasticJob" />
<constructor-arg name="jobName" value="throughputDataFlowElasticJob_no_namespace" />
<constructor-arg name="jobClass" value="com.dangdang.ddframe.job.fixture.ThroughputDataFlowElasticJob" />
<constructor-arg name="shardingTotalCount" value="3" />
<constructor-arg name="cron" value="0/1 * * * * ?" />
Expand Down

0 comments on commit d9d56ff

Please sign in to comment.