@Test
  public void serverNotEnoughWorkerThreadsCausesBindTimerToCloseChannel() throws Exception {
    BlockThreadSmppServerHandler serverHandler0 = new BlockThreadSmppServerHandler();
    SmppServerConfiguration configuration = createSmppServerConfiguration();
    // permit up to 0.5 seconds to bind
    configuration.setBindTimeout(500);
    DefaultSmppServer server0 = new DefaultSmppServer(configuration, serverHandler0);
    server0.start();

    try {
      // there is an issue without telling the server how many worker threads
      // to create beforehand with starvation only Runtime.getRuntime().availableProcessors()
      // worker threads are created by default!!! (yikes)
      int workersToStarveWith = Runtime.getRuntime().availableProcessors();

      // initiate bind requests on all sessions we care about -- this should
      // technicaly "starve" the server of worker threads since they'll all
      // be blocked in a Thread.sleep
      for (int i = 0; i < workersToStarveWith; i++) {
        DefaultSmppClient client0 = new DefaultSmppClient();
        SmppSessionConfiguration sessionConfig0 = createDefaultConfiguration();
        sessionConfig0.setName("WorkerTest.Session." + i);
        // don't use default method of binding, connect the socket first
        DefaultSmppSession session0 =
            client0.doOpen(sessionConfig0, new DefaultSmppSessionHandler());
        // try to bind and execute a bind request and wait for a bind response
        BaseBind bindRequest = client0.createBindRequest(sessionConfig0);
        try {
          // just send the request without caring if it succeeds
          session0.sendRequestPdu(bindRequest, 2000, false);
        } catch (SmppChannelException e) {
          System.out.println(e.getMessage());
        }
      }

      // now try to bind normally -- since all previous workers are "starved"
      // this should fail to bind and the socket closed by the "BindTimer"
      DefaultSmppClient client0 = new DefaultSmppClient();
      SmppSessionConfiguration sessionConfig0 = createDefaultConfiguration();
      sessionConfig0.setName("WorkerTestChannelClosed.Session");
      sessionConfig0.setBindTimeout(750);

      try {
        client0.bind(sessionConfig0);
        Assert.fail();
      } catch (SmppTimeoutException e) {
        // the BindTimer should end up closing the connection since the
        // worker thread were "starved"
        logger.debug("Correctly received SmppChannelException during bind");
      }

    } finally {
      Thread.sleep(10500);
      Assert.assertEquals(0, server0.getChannels().size());
      Assert.assertEquals(3, server0.getCounters().getBindTimeouts());
      server0.destroy();
    }
  }
예제 #2
0
    @Override
    public void sessionBindRequested(
        Long sessionId, SmppSessionConfiguration sessionConfiguration, final BaseBind bindRequest)
        throws SmppProcessingException {
      // test name change of sessions
      // this name actually shows up as thread context....
      sessionConfiguration.setName("Application.SMPP." + sessionConfiguration.getSystemId());

      // throw new SmppProcessingException(SmppConstants.STATUS_BINDFAIL, null);
    }
 public SmppSessionConfiguration createDefaultConfiguration() {
   SmppSessionConfiguration configuration = new SmppSessionConfiguration();
   configuration.setWindowSize(1);
   configuration.setName("Tester.Session.0");
   configuration.setType(SmppBindType.TRANSCEIVER);
   configuration.setHost("localhost");
   configuration.setPort(PORT);
   configuration.setConnectTimeout(100);
   configuration.setBindTimeout(100);
   configuration.setSystemId(SYSTEMID);
   configuration.setPassword(PASSWORD);
   configuration.getLoggingOptions().setLogBytes(true);
   return configuration;
 }
    @Override
    public void sessionBindRequested(
        Long sessionId, SmppSessionConfiguration sessionConfiguration, final BaseBind bindRequest)
        throws SmppProcessingException {
      // test name change of sessions
      sessionConfiguration.setName("Test1");

      if (!SYSTEMID.equals(bindRequest.getSystemId())) {
        throw new SmppProcessingException(SmppConstants.STATUS_INVSYSID);
      }

      if (!PASSWORD.equals(bindRequest.getPassword())) {
        throw new SmppProcessingException(SmppConstants.STATUS_INVPASWD);
      }

      // throw new SmppProcessingException(SmppConstants.STATUS_BINDFAIL, null);
    }
 @Override
 public void sessionBindRequested(
     Long sessionId, SmppSessionConfiguration sessionConfiguration, final BaseBind bindRequest)
     throws SmppProcessingException {
   sessionConfiguration.setName("Application.SMPP." + sessionConfiguration.getSystemId());
 }