-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for #14 - Using Spring AOP/@transactional on an event handler
- Loading branch information
Showing
9 changed files
with
78 additions
and
15 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
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
8 changes: 8 additions & 0 deletions
8
...tests-example/src/main/java/io/eventuate/example/banking/services/counting/Countable.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,8 @@ | ||
package io.eventuate.example.banking.services.counting; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Countable { | ||
} |
25 changes: 25 additions & 0 deletions
25
...rc/main/java/io/eventuate/example/banking/services/counting/InvocationCountingAspect.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,25 @@ | ||
package io.eventuate.example.banking.services.counting; | ||
|
||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.annotation.Before; | ||
import org.aspectj.lang.annotation.Pointcut; | ||
|
||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
@Aspect | ||
public class InvocationCountingAspect { | ||
|
||
@Pointcut("@within(io.eventuate.example.banking.services.counting.Countable) && execution(public void *(..))") | ||
public void invocation() {} | ||
|
||
private AtomicLong counter = new AtomicLong(0); | ||
|
||
@Before("invocation()") | ||
public void countInvocation() { | ||
counter.incrementAndGet(); | ||
} | ||
|
||
public long getCounter() { | ||
return counter.get(); | ||
} | ||
} |
14 changes: 12 additions & 2 deletions
14
...st/java/io/eventuate/javaclient/spring/jdbc/JdbcAutoConfigurationIntegrationSyncTest.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 |
---|---|---|
@@ -1,18 +1,28 @@ | ||
package io.eventuate.javaclient.spring.jdbc; | ||
|
||
import io.eventuate.AggregateRepository; | ||
import io.eventuate.example.banking.services.counting.InvocationCountingAspect; | ||
import io.eventuate.javaclient.spring.tests.common.AbstractAccountIntegrationSyncTest; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.IntegrationTest; | ||
import org.springframework.boot.test.SpringApplicationConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@SpringApplicationConfiguration(classes = JdbcAutoConfigurationIntegrationTestConfiguration.class) | ||
@IntegrationTest | ||
public class JdbcAutoConfigurationIntegrationSyncTest extends AbstractAccountIntegrationSyncTest { | ||
|
||
@Autowired | ||
private InvocationCountingAspect invocationCountingAspect; | ||
|
||
@Override | ||
public void shouldStartMoneyTransfer() throws ExecutionException, InterruptedException { | ||
super.shouldStartMoneyTransfer(); | ||
assertTrue("Expected aspect to be called", invocationCountingAspect.getCounter() > 0); | ||
} | ||
} |
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