@Override public AsyncLogger createLogger(Configuration conf, NamespaceInfo nsInfo, String journalId, InetSocketAddress addr) { AsyncLogger ch = IPCLoggerChannel.FACTORY.createLogger( conf, nsInfo, journalId, addr); AsyncLogger spy = Mockito.spy(ch); Mockito.doAnswer(new SometimesFaulty<Long>(0.10f)) .when(spy).getJournalState(); Mockito.doAnswer(new SometimesFaulty<Void>(0.40f)) .when(spy).newEpoch(Mockito.anyLong()); return spy; }
@Before public void setup() throws Exception { spyLoggers = ImmutableList.of( mockLogger(), mockLogger(), mockLogger()); qjm = new QuorumJournalManager(conf, new URI("qjournal://host/jid"), FAKE_NSINFO) { @Override protected List<AsyncLogger> createLoggers(AsyncLogger.Factory factory) { return spyLoggers; } }; for (AsyncLogger logger : spyLoggers) { futureReturns(GetJournalStateResponseProto.newBuilder() .setLastPromisedEpoch(0) .setHttpPort(-1) .build()) .when(logger).getJournalState(); futureReturns( NewEpochResponseProto.newBuilder().build() ).when(logger).newEpoch(Mockito.anyLong()); futureReturns(null).when(logger).format(Mockito.<NamespaceInfo>any()); } qjm.recoverUnfinalizedSegments(); }
@Override public AsyncLogger createLogger(Configuration conf, NamespaceInfo nsInfo, String journalId, InetSocketAddress addr) { AsyncLogger ch = IPCLoggerChannel.FACTORY.createLogger(conf, nsInfo, journalId, addr); AsyncLogger spy = Mockito.spy(ch); Mockito.doAnswer(new SometimesFaulty<Long>(0.10f)).when(spy) .getJournalState(); Mockito.doAnswer(new SometimesFaulty<Void>(0.40f)).when(spy) .newEpoch(Mockito.anyLong()); return spy; }
@Before public void setup() throws Exception { spyLoggers = ImmutableList.of( mockLogger(), mockLogger(), mockLogger()); qjm = new QuorumJournalManager(conf, new URI("qjournal://host/jid"), FAKE_NSINFO, null, false) { @Override protected List<AsyncLogger> createLoggers(AsyncLogger.Factory factory) { return spyLoggers; } }; for (AsyncLogger logger : spyLoggers) { GetJournalStateResponseProto p = new GetJournalStateResponseProto(); p.setLastPromisedEpoch(0); p.setHttpPort(-1); futureReturns(p) .when(logger).getJournalState(); futureReturns( new NewEpochResponseProto() ).when(logger).newEpoch(Mockito.anyLong()); StartupOption startOpt = null; futureReturns(null).when(logger).transitionJournal( Mockito.<NamespaceInfo> any(), Mockito.eq(Transition.FORMAT), Mockito.eq(startOpt)); } qjm.recoverUnfinalizedSegments(); }
private AsyncLogger mockLogger() { return Mockito.mock(AsyncLogger.class); }