eolivelli 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_r331778329
##########
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:
Isn't this line expected to throw an exception?
----------------------------------------------------------------
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