@Test public void testNothingToSend() throws Exception { SimplexOutgoingSession session = new SimplexOutgoingSession(db, dbExecutor, eventBus, contactId, MAX_LATENCY, streamWriter, recordWriter); Transaction noAckTxn = new Transaction(null, false); Transaction noMsgTxn = new Transaction(null, false); context.checking(new Expectations() {{ oneOf(eventBus).addListener(session); oneOf(db).startTransaction(false); will(returnValue(noAckTxn)); oneOf(db).generateAck(noAckTxn, contactId, MAX_MESSAGE_IDS); will(returnValue(null)); oneOf(db).commitTransaction(noAckTxn); oneOf(db).endTransaction(noAckTxn); oneOf(db).startTransaction(false); will(returnValue(noMsgTxn)); oneOf(db).generateBatch(with(noMsgTxn), with(contactId), with(any(int.class)), with(MAX_LATENCY)); will(returnValue(null)); oneOf(db).commitTransaction(noMsgTxn); oneOf(db).endTransaction(noMsgTxn); oneOf(streamWriter).sendEndOfStream(); oneOf(eventBus).removeListener(session); }}); session.run(); }
@IoExecutor @Override public void run() throws IOException { eventBus.addListener(this); try { dbExecutor.execute(new GenerateAck()); dbExecutor.execute(new GenerateBatch()); try { while (!interrupted) { ThrowingRunnable<IOException> task = writerTasks.take(); if (task == CLOSE) break; task.run(); } streamWriter.sendEndOfStream(); } catch (InterruptedException e) { LOG.info("Interrupted while waiting for a record to write"); Thread.currentThread().interrupt(); } } finally { eventBus.removeListener(this); } }
SimplexOutgoingSession implements SyncSession, EventListener { @IoExecutor @Override public void run() throws IOException { eventBus.addListener(this); try { dbExecutor.execute(new GenerateAck()); dbExecutor.execute(new GenerateBatch()); try { while (!interrupted) { ThrowingRunnable<IOException> task = writerTasks.take(); if (task == CLOSE) break; task.run(); } streamWriter.sendEndOfStream(); } catch (InterruptedException e) { LOG.info("Interrupted while waiting for a record to write"); Thread.currentThread().interrupt(); } } finally { eventBus.removeListener(this); } } }
SimplexOutgoingSession implements SyncSession, EventListener { @IoExecutor @Override public void run() throws IOException { eventBus.addListener(this); try { dbExecutor.execute(new GenerateAck()); dbExecutor.execute(new GenerateBatch()); try { while (!interrupted) { ThrowingRunnable<IOException> task = writerTasks.take(); if (task == CLOSE) break; task.run(); } streamWriter.sendEndOfStream(); } catch (InterruptedException e) { LOG.info("Interrupted while waiting for a record to write"); Thread.currentThread().interrupt(); } } finally { eventBus.removeListener(this); } } SimplexOutgoingSession(DatabaseComponent db, Executor dbExecutor,
			EventBus eventBus, ContactId contactId, int maxLatency,
			StreamWriter streamWriter, SyncRecordWriter recordWriter); }
SimplexOutgoingSession implements SyncSession, EventListener { @IoExecutor @Override public void run() throws IOException { eventBus.addListener(this); try { dbExecutor.execute(new GenerateAck()); dbExecutor.execute(new GenerateBatch()); try { while (!interrupted) { ThrowingRunnable<IOException> task = writerTasks.take(); if (task == CLOSE) break; task.run(); } streamWriter.sendEndOfStream(); } catch (InterruptedException e) { LOG.info("Interrupted while waiting for a record to write"); Thread.currentThread().interrupt(); } } finally { eventBus.removeListener(this); } } SimplexOutgoingSession(DatabaseComponent db, Executor dbExecutor,
			EventBus eventBus, ContactId contactId, int maxLatency,
			StreamWriter streamWriter, SyncRecordWriter recordWriter); @IoExecutor @Override void run(); @Override void interrupt(); @Override void eventOccurred(Event e); }
SimplexOutgoingSession implements SyncSession, EventListener { @IoExecutor @Override public void run() throws IOException { eventBus.addListener(this); try { dbExecutor.execute(new GenerateAck()); dbExecutor.execute(new GenerateBatch()); try { while (!interrupted) { ThrowingRunnable<IOException> task = writerTasks.take(); if (task == CLOSE) break; task.run(); } streamWriter.sendEndOfStream(); } catch (InterruptedException e) { LOG.info("Interrupted while waiting for a record to write"); Thread.currentThread().interrupt(); } } finally { eventBus.removeListener(this); } } SimplexOutgoingSession(DatabaseComponent db, Executor dbExecutor,
			EventBus eventBus, ContactId contactId, int maxLatency,
			StreamWriter streamWriter, SyncRecordWriter recordWriter); @IoExecutor @Override void run(); @Override void interrupt(); @Override void eventOccurred(Event e);  }