コード例 #1
0
 @Test
 public void testInGateway2() {
   DirectFieldAccessor dfa = new DirectFieldAccessor(tcpInboundGateway2);
   assertSame(cfS3, dfa.getPropertyValue("serverConnectionFactory"));
   assertEquals(456L, dfa.getPropertyValue("replyTimeout"));
   assertEquals("inGateway2", tcpInboundGateway2.getComponentName());
   assertEquals("ip:tcp-inbound-gateway", tcpInboundGateway2.getComponentType());
   assertNull(dfa.getPropertyValue("errorChannel"));
   assertEquals(Boolean.FALSE, dfa.getPropertyValue("isClientMode"));
   assertNull(dfa.getPropertyValue("taskScheduler"));
   assertEquals(60000L, dfa.getPropertyValue("retryInterval"));
 }
コード例 #2
0
 @Test
 public void testInGateway1() {
   DirectFieldAccessor dfa = new DirectFieldAccessor(tcpInboundGateway1);
   assertSame(cfS2, dfa.getPropertyValue("serverConnectionFactory"));
   assertEquals(456L, dfa.getPropertyValue("replyTimeout"));
   assertEquals("inGateway1", tcpInboundGateway1.getComponentName());
   assertEquals("ip:tcp-inbound-gateway", tcpInboundGateway1.getComponentType());
   assertEquals(errorChannel, dfa.getPropertyValue("errorChannel"));
   assertTrue(cfS2.isLookupHost());
   assertFalse(tcpInboundGateway1.isAutoStartup());
   assertEquals(126, tcpInboundGateway1.getPhase());
   assertFalse(
       (Boolean)
           TestUtils.getPropertyValue(
               TestUtils.getPropertyValue(cfS2, "mapper"), "applySequence"));
   assertEquals(100L, TestUtils.getPropertyValue(cfS2, "readDelay"));
 }
  private void testRealGuts(
      AbstractClientConnectionFactory client1,
      AbstractClientConnectionFactory client2,
      AbstractServerConnectionFactory server1,
      AbstractServerConnectionFactory server2)
      throws Exception {
    int port1;
    int port2;
    Executor exec = Executors.newCachedThreadPool();
    client1.setTaskExecutor(exec);
    client2.setTaskExecutor(exec);
    server1.setTaskExecutor(exec);
    server2.setTaskExecutor(exec);
    ApplicationEventPublisher pub =
        new ApplicationEventPublisher() {

          @Override
          public void publishEvent(ApplicationEvent event) {}
        };
    client1.setApplicationEventPublisher(pub);
    client2.setApplicationEventPublisher(pub);
    server1.setApplicationEventPublisher(pub);
    server2.setApplicationEventPublisher(pub);
    TcpInboundGateway gateway1 = new TcpInboundGateway();
    gateway1.setConnectionFactory(server1);
    SubscribableChannel channel = new DirectChannel();
    final AtomicReference<String> connectionId = new AtomicReference<String>();
    channel.subscribe(
        new MessageHandler() {
          public void handleMessage(Message<?> message) throws MessagingException {
            connectionId.set((String) message.getHeaders().get(IpHeaders.CONNECTION_ID));
            ((MessageChannel) message.getHeaders().getReplyChannel()).send(message);
          }
        });
    gateway1.setRequestChannel(channel);
    gateway1.start();
    TcpInboundGateway gateway2 = new TcpInboundGateway();
    gateway2.setConnectionFactory(server2);
    gateway2.setRequestChannel(channel);
    gateway2.start();
    TestingUtilities.waitListening(server1, null);
    TestingUtilities.waitListening(server2, null);
    List<AbstractClientConnectionFactory> factories =
        new ArrayList<AbstractClientConnectionFactory>();
    factories.add(client1);
    factories.add(client2);
    FailoverClientConnectionFactory failFactory = new FailoverClientConnectionFactory(factories);
    boolean singleUse = client1.isSingleUse();
    failFactory.setSingleUse(singleUse);
    failFactory.afterPropertiesSet();
    TcpOutboundGateway outGateway = new TcpOutboundGateway();
    outGateway.setConnectionFactory(failFactory);
    outGateway.start();
    QueueChannel replyChannel = new QueueChannel();
    outGateway.setReplyChannel(replyChannel);
    Message<String> message = new GenericMessage<String>("foo");
    outGateway.setRemoteTimeout(120000);
    outGateway.handleMessage(message);
    Socket socket = getSocket(client1);
    port1 = socket.getLocalPort();
    assertTrue(singleUse | connectionId.get().contains(Integer.toString(port1)));
    Message<?> replyMessage = replyChannel.receive(10000);
    assertNotNull(replyMessage);
    server1.stop();
    TestingUtilities.waitUntilFactoryHasThisNumberOfConnections(client1, 0);
    outGateway.handleMessage(message);
    socket = getSocket(client2);
    port2 = socket.getLocalPort();
    assertTrue(singleUse | connectionId.get().contains(Integer.toString(port2)));
    replyMessage = replyChannel.receive(10000);
    assertNotNull(replyMessage);
    gateway2.stop();
    outGateway.stop();
  }