Search in sources :

Example 1 with IdGenerator

use of org.springframework.util.IdGenerator in project spring-integration by spring-projects.

the class MessageIdGenerationTests method testCustomIdGenerationWithChildRegistrarClosed.

@Test
public void testCustomIdGenerationWithChildRegistrarClosed() throws Exception {
    ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context.xml", this.getClass());
    ClassPathXmlApplicationContext child = new ClassPathXmlApplicationContext(new String[] { "MessageIdGenerationTests-context-withGenerator.xml" }, this.getClass(), parent);
    IdGenerator idGenerator = child.getBean("idGenerator", IdGenerator.class);
    Mockito.reset(idGenerator);
    MessageChannel inputChannel = child.getBean("input", MessageChannel.class);
    inputChannel.send(new GenericMessage<Integer>(0));
    verify(idGenerator, atLeastOnce()).generateId();
    child.close();
    parent.close();
    this.assertDestroy();
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) IdGenerator(org.springframework.util.IdGenerator) Test(org.junit.Test)

Example 2 with IdGenerator

use of org.springframework.util.IdGenerator in project spring-integration by spring-projects.

the class MessageIdGenerationTests method testCustomIdGenerationWithParentRegistrar.

@Test
public void testCustomIdGenerationWithParentRegistrar() throws Exception {
    ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context-withGenerator.xml", this.getClass());
    ClassPathXmlApplicationContext child = new ClassPathXmlApplicationContext(new String[] { "MessageIdGenerationTests-context.xml" }, this.getClass(), parent);
    IdGenerator idGenerator = child.getBean("idGenerator", IdGenerator.class);
    MessageChannel inputChannel = child.getBean("input", MessageChannel.class);
    inputChannel.send(new GenericMessage<Integer>(0));
    verify(idGenerator, atLeastOnce()).generateId();
    child.close();
    parent.close();
    this.assertDestroy();
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) IdGenerator(org.springframework.util.IdGenerator) Test(org.junit.Test)

Example 3 with IdGenerator

use of org.springframework.util.IdGenerator in project spring-integration by spring-projects.

the class MessageIdGenerationTests method testCustomIdGenerationWithChildRegistrar.

@Test
public void testCustomIdGenerationWithChildRegistrar() throws Exception {
    ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context.xml", this.getClass());
    ClassPathXmlApplicationContext child = new ClassPathXmlApplicationContext(new String[] { "MessageIdGenerationTests-context-withGenerator.xml" }, this.getClass(), parent);
    IdGenerator idGenerator = child.getBean("idGenerator", IdGenerator.class);
    Mockito.reset(idGenerator);
    MessageChannel inputChannel = child.getBean("input", MessageChannel.class);
    inputChannel.send(new GenericMessage<Integer>(0));
    verify(idGenerator, atLeastOnce()).generateId();
    child.close();
    parent.close();
    this.assertDestroy();
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) IdGenerator(org.springframework.util.IdGenerator) Test(org.junit.Test)

Example 4 with IdGenerator

use of org.springframework.util.IdGenerator in project spring-integration by spring-projects.

the class IdGeneratorConfigurerTests method testJdk.

@Test
public void testJdk() {
    GenericApplicationContext context = new GenericApplicationContext();
    context.registerBeanDefinition("bfpp", new RootBeanDefinition(DefaultConfiguringBeanFactoryPostProcessor.class));
    context.registerBeanDefinition("foo", new RootBeanDefinition(JdkIdGenerator.class));
    context.refresh();
    MessageHeaders headers = new MessageHeaders(null);
    assertSame(context.getBean(IdGenerator.class), TestUtils.getPropertyValue(headers, "idGenerator"));
    context.close();
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) JdkIdGenerator(org.springframework.integration.support.IdGenerators.JdkIdGenerator) MessageHeaders(org.springframework.messaging.MessageHeaders) JdkIdGenerator(org.springframework.integration.support.IdGenerators.JdkIdGenerator) IdGenerator(org.springframework.util.IdGenerator) SimpleIncrementingIdGenerator(org.springframework.integration.support.IdGenerators.SimpleIncrementingIdGenerator) Test(org.junit.Test)

Example 5 with IdGenerator

use of org.springframework.util.IdGenerator in project spring-integration by spring-projects.

the class IdGeneratorConfigurerTests method testIncrementing.

@Test
public void testIncrementing() {
    GenericApplicationContext context = new GenericApplicationContext();
    context.registerBeanDefinition("bfpp", new RootBeanDefinition(DefaultConfiguringBeanFactoryPostProcessor.class));
    context.registerBeanDefinition("foo", new RootBeanDefinition(SimpleIncrementingIdGenerator.class));
    context.refresh();
    IdGenerator idGenerator = context.getBean(IdGenerator.class);
    MessageHeaders headers = new MessageHeaders(null);
    assertEquals(0, headers.getId().getMostSignificantBits());
    assertEquals(1, headers.getId().getLeastSignificantBits());
    headers = new MessageHeaders(null);
    assertEquals(0, headers.getId().getMostSignificantBits());
    assertEquals(2, headers.getId().getLeastSignificantBits());
    AtomicLong bottomBits = TestUtils.getPropertyValue(idGenerator, "bottomBits", AtomicLong.class);
    bottomBits.set(0xffffffff);
    headers = new MessageHeaders(null);
    assertEquals(1, headers.getId().getMostSignificantBits());
    assertEquals(0, headers.getId().getLeastSignificantBits());
    headers = new MessageHeaders(null);
    assertEquals(1, headers.getId().getMostSignificantBits());
    assertEquals(1, headers.getId().getLeastSignificantBits());
    context.close();
}
Also used : SimpleIncrementingIdGenerator(org.springframework.integration.support.IdGenerators.SimpleIncrementingIdGenerator) AtomicLong(java.util.concurrent.atomic.AtomicLong) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) JdkIdGenerator(org.springframework.integration.support.IdGenerators.JdkIdGenerator) IdGenerator(org.springframework.util.IdGenerator) SimpleIncrementingIdGenerator(org.springframework.integration.support.IdGenerators.SimpleIncrementingIdGenerator) MessageHeaders(org.springframework.messaging.MessageHeaders) Test(org.junit.Test)

Aggregations

IdGenerator (org.springframework.util.IdGenerator)10 Test (org.junit.Test)8 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)5 MessageChannel (org.springframework.messaging.MessageChannel)5 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)2 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)2 JdkIdGenerator (org.springframework.integration.support.IdGenerators.JdkIdGenerator)2 SimpleIncrementingIdGenerator (org.springframework.integration.support.IdGenerators.SimpleIncrementingIdGenerator)2 MessageHeaders (org.springframework.messaging.MessageHeaders)2 Field (java.lang.reflect.Field)1 UUID (java.util.UUID)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 BeanDefinitionStoreException (org.springframework.beans.factory.BeanDefinitionStoreException)1 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)1 GenericXmlApplicationContext (org.springframework.context.support.GenericXmlApplicationContext)1