@BeforeClass public static void initialization() { boolean enableSslLbPort = false; boolean terminateTLSTraffic = true; // start lb balancer = new BalancerRunner(); balancer.start(ConfigInit.getLbSpliterProperties(enableSslLbPort, terminateTLSTraffic)); // start servers serverArray = new DefaultSmppServer[serverNumbers]; serverHandlerArray = new DefaultSmppServerHandler[serverNumbers]; for (int i = 0; i < serverNumbers; i++) { serverHandlerArray[i] = new DefaultSmppServerHandler(); serverArray[i] = new DefaultSmppServer( ConfigInit.getSmppServerConfiguration(i, false), serverHandlerArray[i], executor, monitorExecutor); logger.info("Starting SMPP server..."); try { serverArray[i].start(); } catch (SmppChannelException e) { logger.info("SMPP server does not started"); e.printStackTrace(); } logger.info("SMPP server started"); } try { Thread.sleep(2000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
@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(); } }