reddycharan commented on a change in pull request #2173: Call exceptionHandler
if Bookie.start fails with exception.
URL: https://github.com/apache/bookkeeper/pull/2173#discussion_r332762240
##########
File path:
bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieInitializationTest.java
##########
@@ -640,6 +644,67 @@ public void testBookieServiceExceptionHandler() throws
Exception {
startFuture.get();
}
+ public static class MockInterleavedLedgerStorage extends
InterleavedLedgerStorage {
+ AtomicInteger atmoicInt = new AtomicInteger(0);
+
+ @Override
+ public long addEntry(ByteBuf entry) throws IOException {
+ if (atmoicInt.incrementAndGet() == 10) {
+ throw new OutOfMemoryError("Some Injected Exception");
+ }
+ return super.addEntry(entry);
+ }
+ }
+
+ @Test
+ public void testBookieStartException() throws Exception {
+ File journalDir = createTempDir("bookie", "journal");
+ Bookie.checkDirectoryStructure(Bookie.getCurrentDirectory(journalDir));
+
+ File ledgerDir = createTempDir("bookie", "ledger");
+ Bookie.checkDirectoryStructure(Bookie.getCurrentDirectory(ledgerDir));
+
+ /*
+ * add few entries to journal file.
+ */
+ int numOfEntries = 100;
+
BookieJournalTest.writeV5Journal(Bookie.getCurrentDirectory(journalDir),
numOfEntries,
+ "testV5Journal".getBytes());
+
+ /*
+ * This Bookie is configured to use MockInterleavedLedgerStorage.
+ * MockInterleavedLedgerStorage throws an Error for addEntry request.
+ * This is to simulate Bookie/BookieServer/BookieService 'start'
failure
+ * because of 'Bookie.readJournal' failure.
+ */
+ ServerConfiguration conf =
TestBKConfiguration.newServerConfiguration();
+ int port = PortManager.nextFreePort();
+ conf.setBookiePort(port).setJournalDirName(journalDir.getPath())
+ .setLedgerDirNames(new String[] { ledgerDir.getPath()
}).setMetadataServiceUri(metadataServiceUri)
+
.setLedgerStorageClass(MockInterleavedLedgerStorage.class.getName());
+
+ BookieConfiguration bkConf = new BookieConfiguration(conf);
+
+ /*
+ * create cookie and write it to JournalDir/LedgerDir.
+ */
+ Cookie.Builder cookieBuilder = Cookie.generateCookie(conf);
+ Cookie cookie = cookieBuilder.build();
+ cookie.writeToDirectory(new File(journalDir, "current"));
+ cookie.writeToDirectory(new File(ledgerDir, "current"));
+
+ /*
+ * Create LifecycleComponent for BookieServer and start it.
+ */
+ LifecycleComponent server = Main.buildBookieServer(bkConf);
+ CompletableFuture<Void> startFuture =
ComponentStarter.startComponent(server);
+
+ /*
+ * Since Bookie/BookieServer/BookieService is expected to fail to start
+ */
+ startFuture.get();
Review comment:
> Can we verify that the handler has been called?
It is little tricky to test that since the creation and setting of handler
and starting of the component are happening in ComponentStarter.startComponent
method. Anyhow I came up with other solution where we check if the particular
log line saying "exceptionHandler is triggered" is getting logged or not. as
part of this scenario.
> The comment reads 'it is expected to fail' but the future is not failing,
it is not very clear
added more detailed description for what we are doing here.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services