// (timeout = 10000) public void testReConnection() throws Exception { // ignore framework warnings final Logger root = Logger.getRootLogger(); root.setLevel(Level.OFF); final AtomicInteger count = new AtomicInteger(0); final DefaultGnipStream stream = new DefaultGnipStream( new MockRemoteResourceProvider(), "account", "stream", new MockExecutorService(), uriStrategy); final StringBuilder out = new StringBuilder(); final StreamNotification n = new StreamNotification() { @Override public void notifyReConnectionError(final GnipException e) { out.append(String.format("ReConnectionError: %s\n", e.getMessage())); } @Override public void notifyReConnectionAttempt(final int attempt, final long waitTime) { out.append(String.format("Connection attempt %d wait time %d\n", attempt, waitTime)); } @Override public void notifyConnectionError(final TransportGnipException e) { out.append(String.format("ConnectionError: %s\n", e.getMessage())); } @Override public void notify(final Activity activity, final GnipStream stream) { out.append(activity.getBody() + "\n"); if (count.incrementAndGet() >= 4) { stream.close(); } } }; stream.open(n); stream.await(); final String s = out.toString(); final String expected = IOUtils.toString(getClass().getClassLoader().getResourceAsStream("reconnectlog.txt")); Assert.assertEquals(expected, s); Assert.assertEquals( "transferedBytes = 8000\ntransferedActivities = 4\n" + "numberOfSucessfulReconnections = 1\nnumberOfReconnections = 4", stream.getStreamStats().toString()); }
/** setup test */ @Before public void setUp() throws Exception { mapper = DefaultGnipStream.getObjectMapper(); ctx = JAXBContext.newInstance(Activity.class.getPackage().getName()); }