eolivelli commented on a change in pull request #2796:
URL: https://github.com/apache/bookkeeper/pull/2796#discussion_r722966244
##########
File path:
bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieInitializationTest.java
##########
@@ -1614,4 +1614,34 @@ private void testInvalidServiceMetadataURICase(String
uri) throws Exception {
// ok
}
}
+
+ @Test
+ public void testBookieIdSetting() throws Exception {
+ String customBookieId = "customId";
+ // If BookieID is set, it takes precedence over network info.
+ final ServerConfiguration conf =
newServerConfiguration().setBookieId(customBookieId);
+ BookieServer server = new MockBookieServer(conf);
+ server.start();
+ assertEquals(customBookieId, server.getBookieId().toString());
+ server.shutdown();
+ }
+
+ @Test(expected = BookieException.InvalidCookieException.class)
+ public void testBookieIdChange() throws Exception {
+ // By default, network info is set as Bookie Id and it is stored in
the Cookie.
+ final ServerConfiguration conf = newServerConfiguration();
+ BookieServer server = new MockBookieServer(conf);
+ server.start();
+ assertNotNull(server.getBookieId().toString());
+ server.shutdown();
+
+ // If BookieID is set, it takes precedence over network info. Because
of that, the new Bookie start
+ // should fail with an InvalidCookieException, as now the custom
BookieID takes precedence.
+ String customBookieId = "customId";
+ conf.setBookieId(customBookieId);
+ server = new MockBookieServer(conf);
+ server.start();
+ assertEquals(customBookieId, server.getBookieId().toString());
+ server.shutdown();
Review comment:
very good point @dlg99
we should verify the Exception in a `catch` block and call "shutdown" in a
`finally` block in order to perform any cleanup that is needed (and do not fall
into leaks)
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]