Search in sources :

Example 1 with PriorityChannel

use of org.springframework.integration.channel.PriorityChannel in project spring-integration by spring-projects.

the class ChannelCapacityPlaceholderTests method testCapacityOnPriorityChannel.

@Test
public void testCapacityOnPriorityChannel() {
    PriorityChannel channel = context.getBean("priorityChannel", PriorityChannel.class);
    assertNotNull(channel);
    assertEquals(99, channel.getRemainingCapacity());
    channel.send(MessageBuilder.withPayload("test1").build());
    channel.send(MessageBuilder.withPayload("test2").build());
    assertEquals(97, channel.getRemainingCapacity());
    assertNotNull(channel.receive(0));
    assertEquals(98, channel.getRemainingCapacity());
}
Also used : PriorityChannel(org.springframework.integration.channel.PriorityChannel) Test(org.junit.Test)

Example 2 with PriorityChannel

use of org.springframework.integration.channel.PriorityChannel in project spring-integration by spring-projects.

the class ConfigurableMongoDbMessageGroupStoreTests method testPriorityChannel.

@Test
@MongoDbAvailable
public void testPriorityChannel() throws Exception {
    this.cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("ConfigurableMongoDbMessageStore-CustomConverter.xml", this.getClass());
    context.refresh();
    Object priorityChannel = context.getBean("priorityChannel");
    assertThat(priorityChannel, Matchers.instanceOf(PriorityChannel.class));
    QueueChannel channel = (QueueChannel) priorityChannel;
    Message<String> message = MessageBuilder.withPayload("1").setHeader(IntegrationMessageHeaderAccessor.PRIORITY, 1).build();
    channel.send(message);
    message = MessageBuilder.withPayload("-1").setHeader(IntegrationMessageHeaderAccessor.PRIORITY, -1).build();
    channel.send(message);
    message = MessageBuilder.withPayload("3").setHeader(IntegrationMessageHeaderAccessor.PRIORITY, 3).build();
    channel.send(message);
    message = MessageBuilder.withPayload("0").setHeader(IntegrationMessageHeaderAccessor.PRIORITY, 0).build();
    channel.send(message);
    message = MessageBuilder.withPayload("2").setHeader(IntegrationMessageHeaderAccessor.PRIORITY, 2).build();
    channel.send(message);
    message = MessageBuilder.withPayload("none").build();
    channel.send(message);
    message = MessageBuilder.withPayload("31").setHeader(IntegrationMessageHeaderAccessor.PRIORITY, 3).build();
    channel.send(message);
    Message<?> receive = channel.receive(1000);
    assertNotNull(receive);
    assertEquals("3", receive.getPayload());
    receive = channel.receive(1000);
    assertNotNull(receive);
    assertEquals("31", receive.getPayload());
    receive = channel.receive(1000);
    assertNotNull(receive);
    assertEquals("2", receive.getPayload());
    receive = channel.receive(1000);
    assertNotNull(receive);
    assertEquals("1", receive.getPayload());
    receive = channel.receive(1000);
    assertNotNull(receive);
    assertEquals("0", receive.getPayload());
    receive = channel.receive(1000);
    assertNotNull(receive);
    assertEquals("-1", receive.getPayload());
    receive = channel.receive(1000);
    assertNotNull(receive);
    assertEquals("none", receive.getPayload());
    context.close();
}
Also used : MongoClient(com.mongodb.MongoClient) SimpleMongoDbFactory(org.springframework.data.mongodb.core.SimpleMongoDbFactory) QueueChannel(org.springframework.integration.channel.QueueChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PriorityChannel(org.springframework.integration.channel.PriorityChannel) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Aggregations

Test (org.junit.Test)2 PriorityChannel (org.springframework.integration.channel.PriorityChannel)2 MongoClient (com.mongodb.MongoClient)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1 SimpleMongoDbFactory (org.springframework.data.mongodb.core.SimpleMongoDbFactory)1 QueueChannel (org.springframework.integration.channel.QueueChannel)1 MongoDbAvailable (org.springframework.integration.mongodb.rules.MongoDbAvailable)1