-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: the issue of incorrect annotation retrieval from the proxy ob…
…ject (#7107)
- Loading branch information
1 parent
02e1514
commit f02d0fe
Showing
10 changed files
with
268 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
spring/src/test/java/org/apache/seata/spring/SpringLocalTccTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* 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.seata.spring; | ||
|
||
import java.io.IOException; | ||
import org.apache.seata.integration.tx.api.interceptor.handler.ProxyInvocationHandler; | ||
import org.apache.seata.rm.tcc.interceptor.parser.TccActionInterceptorParser; | ||
import org.apache.seata.spring.tcc.TccAnnoAtInterAction; | ||
import org.apache.seata.spring.tcc.TccAnnoAtInterActionImpl; | ||
import org.apache.seata.spring.tcc.TccAnnoAtInterImplAction; | ||
import org.apache.seata.spring.tcc.TccAnnoAtInterImplActionImpl; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.aop.MethodBeforeAdvice; | ||
import org.springframework.aop.framework.ProxyFactory; | ||
import org.springframework.aop.support.NameMatchMethodPointcutAdvisor; | ||
|
||
|
||
public class SpringLocalTccTest { | ||
|
||
|
||
@BeforeAll | ||
public static void init() throws IOException { | ||
System.setProperty("config.type", "file"); | ||
System.setProperty("config.file.name", "file.conf"); | ||
System.setProperty("txServiceGroup", "default_tx_group"); | ||
System.setProperty("service.vgroupMapping.default_tx_group", "default"); | ||
} | ||
|
||
@Test | ||
void testParserInterfaceToProxyForSpringCGLIB() throws Exception { | ||
//local tcc anno at interface impl | ||
{ | ||
TccActionInterceptorParser tccActionInterceptorParser = new TccActionInterceptorParser(); | ||
TccAnnoAtInterImplActionImpl tccAction = new TccAnnoAtInterImplActionImpl(); | ||
TccAnnoAtInterImplAction proxyTccAction = createSpringCGLIBProxy(tccAction, "doSomething", TccAnnoAtInterImplAction.class); | ||
ProxyInvocationHandler proxyInvocationHandler = tccActionInterceptorParser.parserInterfaceToProxy(proxyTccAction, proxyTccAction.getClass().getName()); | ||
Assertions.assertNotNull(proxyInvocationHandler); | ||
} | ||
|
||
//local tcc anno at interface | ||
{ | ||
TccActionInterceptorParser tccActionInterceptorParser = new TccActionInterceptorParser(); | ||
TccAnnoAtInterActionImpl tccAction = new TccAnnoAtInterActionImpl(); | ||
TccAnnoAtInterAction proxyTccAction = createSpringCGLIBProxy(tccAction, "doSomething", TccAnnoAtInterAction.class); | ||
ProxyInvocationHandler proxyInvocationHandler = tccActionInterceptorParser.parserInterfaceToProxy(proxyTccAction, proxyTccAction.getClass().getName()); | ||
Assertions.assertNotNull(proxyInvocationHandler); | ||
} | ||
} | ||
|
||
private <T> T createSpringCGLIBProxy(T target, String methodName, Class<T> interfaceClass) { | ||
ProxyFactory proxyFactory = new ProxyFactory(target); | ||
proxyFactory.setProxyTargetClass(true); | ||
MethodBeforeAdvice advice = (method, args1, target1) -> System.out.println("test"); | ||
NameMatchMethodPointcutAdvisor advisor = new NameMatchMethodPointcutAdvisor(advice); | ||
advisor.addMethodName(methodName); | ||
proxyFactory.addAdvisor(advisor); | ||
return interfaceClass.cast(proxyFactory.getProxy()); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
spring/src/test/java/org/apache/seata/spring/tcc/TccAnnoAtInterAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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.seata.spring.tcc; | ||
|
||
import org.apache.seata.rm.tcc.api.BusinessActionContext; | ||
import org.apache.seata.rm.tcc.api.LocalTCC; | ||
import org.apache.seata.rm.tcc.api.TwoPhaseBusinessAction; | ||
|
||
@LocalTCC | ||
public interface TccAnnoAtInterAction { | ||
|
||
/** | ||
* Prepare boolean. | ||
* | ||
* @param actionContext the action context | ||
* @return the boolean | ||
*/ | ||
@TwoPhaseBusinessAction(name = "TccAnnoAtInterAction", commitMethod = "commit", rollbackMethod = "rollback") | ||
boolean prepare(BusinessActionContext actionContext); | ||
|
||
/** | ||
* Commit boolean. | ||
* | ||
* @param actionContext the action context | ||
* @return the boolean | ||
*/ | ||
boolean commit(BusinessActionContext actionContext); | ||
|
||
/** | ||
* Rollback boolean. | ||
* | ||
* @param actionContext the action context | ||
* @return the boolean | ||
*/ | ||
boolean rollback(BusinessActionContext actionContext); | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
spring/src/test/java/org/apache/seata/spring/tcc/TccAnnoAtInterActionImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.seata.spring.tcc; | ||
|
||
import org.apache.seata.rm.tcc.api.BusinessActionContext; | ||
|
||
public class TccAnnoAtInterActionImpl implements TccAnnoAtInterAction { | ||
|
||
@Override | ||
public boolean prepare(BusinessActionContext actionContext) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean commit(BusinessActionContext actionContext) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean rollback(BusinessActionContext actionContext) { | ||
return false; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
spring/src/test/java/org/apache/seata/spring/tcc/TccAnnoAtInterImplAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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.seata.spring.tcc; | ||
|
||
import org.apache.seata.rm.tcc.api.BusinessActionContext; | ||
|
||
|
||
public interface TccAnnoAtInterImplAction { | ||
|
||
/** | ||
* Prepare boolean. | ||
* | ||
* @param actionContext the action context | ||
* @return the boolean | ||
*/ | ||
boolean prepare(BusinessActionContext actionContext); | ||
|
||
/** | ||
* Commit boolean. | ||
* | ||
* @param actionContext the action context | ||
* @return the boolean | ||
*/ | ||
boolean commit(BusinessActionContext actionContext); | ||
|
||
/** | ||
* Rollback boolean. | ||
* | ||
* @param actionContext the action context | ||
* @return the boolean | ||
*/ | ||
boolean rollback(BusinessActionContext actionContext); | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
spring/src/test/java/org/apache/seata/spring/tcc/TccAnnoAtInterImplActionImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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.seata.spring.tcc; | ||
|
||
import org.apache.seata.rm.tcc.api.BusinessActionContext; | ||
import org.apache.seata.rm.tcc.api.LocalTCC; | ||
import org.apache.seata.rm.tcc.api.TwoPhaseBusinessAction; | ||
|
||
|
||
@LocalTCC | ||
public class TccAnnoAtInterImplActionImpl implements TccAnnoAtInterImplAction { | ||
|
||
@Override | ||
@TwoPhaseBusinessAction(name = "TccAnnoAtInterImplAction", commitMethod = "commit", rollbackMethod = "rollback") | ||
public boolean prepare(BusinessActionContext actionContext) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean commit(BusinessActionContext actionContext) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean rollback(BusinessActionContext actionContext) { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters