Skip to content

Commit

Permalink
fix #78
Browse files Browse the repository at this point in the history
  • Loading branch information
haocao committed Mar 28, 2016
1 parent 5dea52c commit aebcba7
Show file tree
Hide file tree
Showing 21 changed files with 355 additions and 100 deletions.
1 change: 1 addition & 0 deletions elastic-job-doc/content/post/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ weight=1
### 缺陷修正

1. [ISSUE #74](https://github.com/dangdangdotcom/elastic-job/issues/74) 流式处理且失效转移时,失效转移的分片项不能执行一次即停止
1. [ISSUE #78](https://github.com/dangdangdotcom/elastic-job/issues/78) Spring方式配置作业监听启用AOP导致不能正常使用问题

## 1.0.5

Expand Down
8 changes: 8 additions & 0 deletions elastic-job-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Properties;

import com.dangdang.ddframe.job.api.listener.ElasticJobListener;
import com.dangdang.ddframe.job.spring.util.AopTargetUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

Expand All @@ -41,7 +42,15 @@ public SpringJobScheduler(final CoordinatorRegistryCenter coordinatorRegistryCen
}

public SpringJobScheduler(final CoordinatorRegistryCenter coordinatorRegistryCenter, final JobConfiguration jobConfiguration, final ElasticJobListener[] elasticJobListeners) {
super(coordinatorRegistryCenter, jobConfiguration, elasticJobListeners);
super(coordinatorRegistryCenter, jobConfiguration, getTargetElasticJobListeners(elasticJobListeners));
}

private static ElasticJobListener[] getTargetElasticJobListeners(ElasticJobListener[] elasticJobListeners) {
final ElasticJobListener[] result = new ElasticJobListener[elasticJobListeners.length];
for (int i = 0; i < elasticJobListeners.length; i++) {
result[i] = (ElasticJobListener) AopTargetUtils.getTarget(elasticJobListeners[i]);
}
return result;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@

package com.dangdang.ddframe.job;

import com.dangdang.ddframe.job.spring.WithNamespaceAndListenerTest;
import com.dangdang.ddframe.job.spring.*;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

import com.dangdang.ddframe.job.spring.WithNamespaceTest;
import com.dangdang.ddframe.job.spring.WithoutNamespaceTest;

@RunWith(Suite.class)
@SuiteClasses({
WithNamespaceTest.class,
WithNamespaceAndListenerTest.class,
WithNamespaceAndListenerAndJdkDynamicProxyTest.class,
WithNamespaceAndListenerAndCglibTest.class,
WithoutNamespaceTest.class
})
public class AllSpringJobTests {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* *
* * Copyright 1999-2015 dangdang.com.
* * <p>
* * Licensed 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.
* * </p>
*
*
*/

package com.dangdang.ddframe.job.fixture.aspect;

import org.aspectj.lang.JoinPoint;
import org.springframework.stereotype.Component;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

@Component
@Aspect
public class SimpleAspect {

@Pointcut("execution(* com.dangdang.ddframe.job.fixture..*(..))")
public void aspect(){
}

@Before("aspect()")
public void before(JoinPoint joinPoint){
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* *
* * Copyright 1999-2015 dangdang.com.
* * <p>
* * Licensed 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.
* * </p>
*
*
*/

package com.dangdang.ddframe.job.fixture.listener;

import com.dangdang.ddframe.job.api.JobExecutionMultipleShardingContext;
import com.dangdang.ddframe.job.api.listener.ElasticJobListener;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

public class SimpleCglibListener implements ElasticJobListener {

@Override
public void beforeJobExecuted(JobExecutionMultipleShardingContext shardingContext) {
assertThat(shardingContext.getJobName(), is("simpleElasticJob_namespace_listener_cglib"));
}

@Override
public void afterJobExecuted(JobExecutionMultipleShardingContext shardingContext) {
assertThat(shardingContext.getJobName(), is("simpleElasticJob_namespace_listener_cglib"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* *
* * Copyright 1999-2015 dangdang.com.
* * <p>
* * Licensed 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.
* * </p>
*
*
*/

package com.dangdang.ddframe.job.fixture.listener;

import com.dangdang.ddframe.job.api.JobExecutionMultipleShardingContext;
import com.dangdang.ddframe.job.api.listener.ElasticJobListener;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

public class SimpleJdkDynamicProxyListener implements ElasticJobListener {

@Override
public void beforeJobExecuted(JobExecutionMultipleShardingContext shardingContext) {
assertThat(shardingContext.getJobName(), is("simpleElasticJob_namespace_listener_jdk_proxy"));
}

@Override
public void afterJobExecuted(JobExecutionMultipleShardingContext shardingContext) {
assertThat(shardingContext.getJobName(), is("simpleElasticJob_namespace_listener_jdk_proxy"));
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
/*
* Copyright 1999-2015 dangdang.com.
* <p>
* Licensed 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
* *
* * Copyright 1999-2015 dangdang.com.
* * <p>
* * Licensed 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.
* * </p>
*
*
* 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.
* </p>
*/

package com.dangdang.ddframe.job.fixture;
package com.dangdang.ddframe.job.fixture.listener;

import com.dangdang.ddframe.job.api.JobExecutionMultipleShardingContext;
import com.dangdang.ddframe.job.api.listener.AbstractDistributeOnceElasticJobListener;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
/*
* Copyright 1999-2015 dangdang.com.
* <p>
* Licensed 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
* *
* * Copyright 1999-2015 dangdang.com.
* * <p>
* * Licensed 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.
* * </p>
*
*
* 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.
* </p>
*/

package com.dangdang.ddframe.job.fixture;
package com.dangdang.ddframe.job.fixture.listener;

import com.dangdang.ddframe.job.api.JobExecutionMultipleShardingContext;
import com.dangdang.ddframe.job.api.listener.AbstractDistributeOnceElasticJobListener;
import com.dangdang.ddframe.job.fixture.service.FooService;

import javax.annotation.Resource;

Expand All @@ -42,12 +46,12 @@ public SimpleOnceListener(final long startedTimeoutMilliseconds, final long comp

@Override
public void doBeforeJobExecutedAtLastStarted(final JobExecutionMultipleShardingContext shardingContext) {
assertThat(startedTimeoutMilliseconds, is(1000L));
assertThat(startedTimeoutMilliseconds, is(10000L));
assertThat(fooService.foo(), is("this is fooService."));
}

@Override
public void doAfterJobExecutedAtLastCompleted(final JobExecutionMultipleShardingContext shardingContext) {
assertThat(completedTimeoutMilliseconds, is(2000L));
assertThat(completedTimeoutMilliseconds, is(20000L));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* *
* * Copyright 1999-2015 dangdang.com.
* * <p>
* * Licensed 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.
* * </p>
*
*
*/

package com.dangdang.ddframe.job.fixture.service;

public interface FooService {

String foo();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* *
* * Copyright 1999-2015 dangdang.com.
* * <p>
* * Licensed 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.
* * </p>
*
*
*/

package com.dangdang.ddframe.job.fixture.service;

public class FooServiceImpl implements FooService {

@Override
public String foo() {
return "this is fooService.";
}
}
Loading

0 comments on commit aebcba7

Please sign in to comment.