INT-1903 polishing

This commit is contained in:
Oleg Zhurakousky
2011-05-16 16:57:13 -04:00
parent 5bf5d1f145
commit 0cb3c14603
5 changed files with 132 additions and 36 deletions

View File

@@ -5,11 +5,11 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd">
<bean id="idGenerator" class="org.mockito.Mockito" factory-method="spy">
<constructor-arg>
<bean class="org.springframework.integration.core.MessageIdGenerationTests.SampleIdGenerator"/>
</constructor-arg>
</bean>
<!-- <bean id="idGenerator" class="org.mockito.Mockito" factory-method="spy"> -->
<!-- <constructor-arg> -->
<!-- <bean class="org.springframework.integration.core.MessageIdGenerationTests.SampleIdGenerator"/> -->
<!-- </constructor-arg> -->
<!-- </bean> -->
<int:channel id="input"/>

View File

@@ -25,6 +25,7 @@ import java.util.UUID;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.MessageHeaders;
@@ -39,19 +40,69 @@ import org.springframework.util.StopWatch;
*/
public class MessageIdGenerationTests {
@Test
public void testCustomIdGeneration(){
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context.xml", this.getClass());
public void testCustomIdGenerationWithParentRegistrar(){
ApplicationContext ctx = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context-a.xml", this.getClass());
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"MessageIdGenerationTests-context.xml"}, this.getClass(), ctx);
IdGenerator idGenerator = context.getBean("idGenerator", IdGenerator.class);
MessageChannel inputChannel = context.getBean("input", MessageChannel.class);
inputChannel.send(new GenericMessage<Integer>(0));
verify(idGenerator, times(4)).generateId();
reset(idGenerator);
context.destroy();
context.close();
new GenericMessage<Integer>(0);
verify(idGenerator, times(1)).generateId();
}
@Test
public void testCustomIdGenerationWithParentRegistrarClosed(){
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context-a.xml", this.getClass());
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"MessageIdGenerationTests-context.xml"}, this.getClass(), ctx);
IdGenerator idGenerator = context.getBean("idGenerator", IdGenerator.class);
MessageChannel inputChannel = context.getBean("input", MessageChannel.class);
inputChannel.send(new GenericMessage<Integer>(0));
verify(idGenerator, times(4)).generateId();
reset(idGenerator);
ctx.close();
new GenericMessage<Integer>(0);
verify(idGenerator, times(0)).generateId();
}
@Test
public void testCustomIdGenerationWithChildRegistrar(){
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context.xml", this.getClass());
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"MessageIdGenerationTests-context-a.xml"}, this.getClass(), ctx);
IdGenerator idGenerator = context.getBean("idGenerator", IdGenerator.class);
MessageChannel inputChannel = context.getBean("input", MessageChannel.class);
inputChannel.send(new GenericMessage<Integer>(0));
verify(idGenerator, times(4)).generateId();
reset(idGenerator);
ctx.close();
new GenericMessage<Integer>(0);
verify(idGenerator, times(1)).generateId();
}
@Test
public void testCustomIdGenerationWithChildRegistrarClosed(){
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context.xml", this.getClass());
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"MessageIdGenerationTests-context-a.xml"}, this.getClass(), ctx);
IdGenerator idGenerator = context.getBean("idGenerator", IdGenerator.class);
MessageChannel inputChannel = context.getBean("input", MessageChannel.class);
inputChannel.send(new GenericMessage<Integer>(0));
verify(idGenerator, times(4)).generateId();
reset(idGenerator);
context.close();
new GenericMessage<Integer>(0);
verify(idGenerator, times(0)).generateId();
}
@Test
@Ignore
public void performanceTest(){
@@ -91,6 +142,19 @@ public class MessageIdGenerationTests {
public static class SampleIdGenerator implements IdGenerator {
public SampleIdGenerator(){
System.out.println("Generator");
}
public UUID generateId() {
return UUID.nameUUIDFromBytes(((System.currentTimeMillis() - System.nanoTime()) + "").getBytes());
}
}
public static class SampleIdGeneratorA implements IdGenerator {
public SampleIdGeneratorA(){
System.out.println("Generator A");
}
public UUID generateId() {
return UUID.nameUUIDFromBytes(((System.currentTimeMillis() - System.nanoTime()) + "").getBytes());