throw new C2ServiceException("simulated timeout, the internet is down.",true);
}
}
};
C2EntryServiceJournal journal = new C2EntryServiceMemoryJournal() {
@Override
public Iterator<Request> pending() {
return super.pending();
}
@Override
public void append(Request request) {
assertEquals("*****",request.get(Parameter.Password));
super.append(request);
}
@Override
public void markSent(Request request) {
Request oldest = super.pending().next();
assertEquals("\n"+request+"\n"+oldest ,
request, oldest);
super.markSent(request);
}
@Override
public Request[] dropPending() {
return super.dropPending();
}
};
C2ServiceFactory factory = new C2ServiceFactory(simulationAdapter, journal);
String password = "PA55WORD";
Integer systemId = 99999999;
String eMail = "someone@somewhere.com";
C2EntryService sentryService = factory.signalEntryService(password, systemId, eMail);
lock.lock(); //prevent transmit
ImplResponse allSys = (ImplResponse)sentryService.sendAllSystemsRequest();
ImplResponse allSig = (ImplResponse)sentryService.sendAllSignalsRequest();
//check that everything got saved
Iterator<Request> pending = journal.pending();
assertTrue(pending.hasNext());
assertEquals(allSys.secureRequest(),pending.next());
assertTrue(pending.hasNext());
assertEquals(allSig.secureRequest().secureClone(), pending.next());
assertFalse(pending.hasNext());
//Now dump and rebuild factory from scratch so its forced to build response list.
//sentryService.awaitPending();//.shutdown();//must stop old daemon before starting new one
lock.unlock();
factory = new C2ServiceFactory(simulationAdapter, journal);
sentryService = factory.signalEntryService(password, systemId, eMail);
sentryService.awaitPending();
assertFalse(journal.pending().hasNext());
}