@Test public void testDisconnectViaExceeded() { // Make the test run a little faster SystemProperties.setProperty("ss.echo_sender_interval", "1"); SystemProperties.setProperty("ss.echo_max_missed_echos", "2"); // Instatiate the resource ResourceImpl resourceImpl = new ResourceImpl(restItem); try { channel.queueDeclare(intTestQueue, false, false, false, null); } catch (Exception ex) { fail("Connectivity error to MQ while running Test" + ex); try { channel.close(); connection.close(); } catch (Exception otherEx) { // We couldn't close a connection that's already closed or // hasn't been open... } } // Here we build the queue ResourceImpl is going to connect to and we // will later publish to try { resourceImpl.startStreaming(createListeners()); } catch (Exception ex) { fail("Error while starting streaming service: " + ex); } // Have a rest to let the echo count expire try { Thread.sleep(30000); } catch (Exception ex) { fail("Interrupted sleep cycle" + ex); } // 1st test: did the echo count get increased by the batch echo sends? assertTrue(disconnectedEventCalled); try { channel.queuePurge(resourceId); channel.close(); connection.close(); } catch (Exception otherEx) { // We couldn't close a connection that's already closed or hasn't // been open... } }
@Before public void setUp() throws Exception { HttpServices.setHttpServices(mock(HttpServices.class)); EchoSender.terminate(); MQListener.terminate(); WorkQueueMonitor.terminate(); if (svcThreadRunning == false) { ServiceThreadExecutor.createExecutor(); svcThreadRunning = true; } /* * CtagResourceMap.reset(); EchoResourceMap.reset(); * ResourceWorkerMap.reset(); ResourceWorkQueue.reset(); * WorkQueue.reset(); */ ResourceWorkerMap.initWorkerMap(); SystemProperties.setProperty("ss.echo_sender_interval", "20"); SystemProperties.setProperty("ss.echo_max_missed_echos", "3"); connFactory = new ConnectionFactory(); connFactory.setHost("127.0.0.1"); connFactory.setVirtualHost("/fern"); connFactory.setUsername("sportingsolutions@fern"); connFactory.setPassword("sporting"); connection = connFactory.newConnection(); channel = connection.createChannel(); // Prepare test data to create the Resource requestItems = JsonHelper.toRestItems(resources); requestSR = new ServiceRequest(); // requestSR.setAuthToken("AUTH_TOKEN_01"); requestSR.setServiceRestItems(requestItems); restItem = getRestItems(requestSR, "Fern v NotFern"); String responseAMQEndPoint = "[{\"Name\":\"stream\",\"Links\":[{\"Relation\":\"amqp\",\"Href\":\"amqp://sportingsolutions%40fern:[email protected]:5672/fern/" + intTestQueue + "\"}]}]"; responseItems = JsonHelper.toRestItems(responseAMQEndPoint); // responseSR.setAuthToken("AUTH_TOKEN_01"); responseSR.setServiceRestItems(responseItems); // Here we mock http services. It still's try to connect but we have a // response ready for the call doAnswer( new Answer<ServiceRequest>() { public ServiceRequest answer(InvocationOnMock invocation) throws Throwable { return responseSR; } }) .when(HttpServices.getHttpService()) .processRequest( "http://api.sportingsolutions.com/rels/stream/amqp", restItem, "Fern v NotFern"); connectedEventCalled = false; disconnectedEventCalled = false; streamEventCalled = false; }