|
19 | 19 | package org.apache.bookkeeper.server.http; |
20 | 20 |
|
21 | 21 | import static org.apache.bookkeeper.meta.MetadataDrivers.runFunctionWithLedgerManagerFactory; |
| 22 | +import static org.apache.bookkeeper.meta.MetadataDrivers.runFunctionWithRegistrationManager; |
22 | 23 | import static org.junit.jupiter.api.Assertions.assertEquals; |
23 | 24 | import static org.junit.jupiter.api.Assertions.assertFalse; |
24 | 25 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
|
37 | 38 | import java.util.List; |
38 | 39 | import java.util.Map; |
39 | 40 | import java.util.concurrent.Future; |
| 41 | +import java.util.concurrent.TimeUnit; |
40 | 42 | import lombok.Cleanup; |
| 43 | +import org.apache.bookkeeper.bookie.BookieException; |
41 | 44 | import org.apache.bookkeeper.bookie.BookieResources; |
| 45 | +import org.apache.bookkeeper.bookie.Cookie; |
42 | 46 | import org.apache.bookkeeper.bookie.LedgerStorage; |
43 | 47 | import org.apache.bookkeeper.client.BookKeeper; |
44 | 48 | import org.apache.bookkeeper.client.ClientUtil; |
|
55 | 59 | import org.apache.bookkeeper.meta.LedgerManagerFactory; |
56 | 60 | import org.apache.bookkeeper.meta.LedgerUnderreplicationManager; |
57 | 61 | import org.apache.bookkeeper.meta.MetadataBookieDriver; |
| 62 | +import org.apache.bookkeeper.net.BookieId; |
58 | 63 | import org.apache.bookkeeper.net.BookieSocketAddress; |
59 | 64 | import org.apache.bookkeeper.proto.BookieServer; |
60 | 65 | import org.apache.bookkeeper.replication.AuditorElector; |
|
66 | 71 | import org.apache.bookkeeper.server.http.service.ClusterInfoService; |
67 | 72 | import org.apache.bookkeeper.stats.NullStatsLogger; |
68 | 73 | import org.apache.bookkeeper.test.BookKeeperClusterTestCase; |
| 74 | +import org.apache.bookkeeper.versioning.Versioned; |
| 75 | +import org.awaitility.Awaitility; |
69 | 76 | import org.junit.jupiter.api.AfterEach; |
70 | 77 | import org.junit.jupiter.api.BeforeEach; |
71 | 78 | import org.junit.jupiter.api.Test; |
@@ -765,15 +772,61 @@ public void testDecommissionService() throws Exception { |
765 | 772 | assertEquals(HttpServer.StatusCode.NOT_FOUND.getValue(), response2.getStatusCode()); |
766 | 773 |
|
767 | 774 | //3, PUT, with body, should success. |
768 | | - String putBody3 = "{\"bookie_src\": \"" + getBookie(1).toString() + "\"}"; |
| 775 | + BookieId bookieId = getBookie(1); |
| 776 | + String putBody3 = "{\"bookie_src\": \"" + bookieId.toString() + "\"}"; |
769 | 777 | HttpServiceRequest request3 = new HttpServiceRequest(putBody3, HttpServer.Method.PUT, null); |
770 | 778 | // after bookie kill, request should success |
771 | 779 | killBookie(1); |
772 | 780 | HttpServiceResponse response3 = decommissionService.handle(request3); |
773 | 781 | assertEquals(HttpServer.StatusCode.OK.getValue(), response3.getStatusCode()); |
| 782 | + // wait decommission finish |
| 783 | + Awaitility.await().pollDelay(60, TimeUnit.SECONDS).timeout(70, TimeUnit.SECONDS).untilAsserted(() -> { |
| 784 | + runFunctionWithRegistrationManager(baseConf, registrationManager -> { |
| 785 | + Versioned<Cookie> cookieFromZk = null; |
| 786 | + try { |
| 787 | + cookieFromZk = Cookie.readFromRegistrationManager(registrationManager, |
| 788 | + bookieId); |
| 789 | + } catch (BookieException e) { |
| 790 | + } finally { |
| 791 | + assertTrue(cookieFromZk != null); |
| 792 | + } |
| 793 | + return true; |
| 794 | + }); |
| 795 | + }); |
774 | 796 | stopAuditorElector(); |
775 | 797 | } |
776 | 798 |
|
| 799 | + @Test |
| 800 | + public void testDecommissionServiceWithDeleteCookie() throws Exception { |
| 801 | + baseConf.setMetadataServiceUri(zkUtil.getMetadataServiceUri()); |
| 802 | + startReplicationService(); |
| 803 | + |
| 804 | + HttpEndpointService decommissionService = bkHttpServiceProvider |
| 805 | + .provideHttpEndpointService(HttpServer.ApiType.DECOMMISSION); |
| 806 | + BookieId bookieId = getBookie(1); |
| 807 | + String putBody1 = "{\"bookie_src\": \"" + bookieId.toString() + "\", \"delete_cookie\": \"true\"}"; |
| 808 | + HttpServiceRequest request1 = new HttpServiceRequest(putBody1, HttpServer.Method.PUT, null); |
| 809 | + // after bookie kill, request should success |
| 810 | + killBookie(1); |
| 811 | + HttpServiceResponse response1 = decommissionService.handle(request1); |
| 812 | + assertEquals(HttpServer.StatusCode.OK.getValue(), response1.getStatusCode()); |
| 813 | + // wait decommission finish |
| 814 | + Awaitility.await().pollInterval(10, TimeUnit.SECONDS).timeout(60, TimeUnit.SECONDS).untilAsserted(() -> { |
| 815 | + runFunctionWithRegistrationManager(baseConf, registrationManager -> { |
| 816 | + Versioned<Cookie> cookieFromZk = null; |
| 817 | + try { |
| 818 | + cookieFromZk = Cookie.readFromRegistrationManager(registrationManager, |
| 819 | + bookieId); |
| 820 | + } catch (Exception e) { |
| 821 | + } finally { |
| 822 | + assertTrue(cookieFromZk == null); |
| 823 | + } |
| 824 | + return true; |
| 825 | + }); |
| 826 | + }); |
| 827 | + stopReplicationService(); |
| 828 | + } |
| 829 | + |
777 | 830 | @Test |
778 | 831 | public void testTriggerGCService() throws Exception { |
779 | 832 | baseConf.setMetadataServiceUri(zkUtil.getMetadataServiceUri()); |
|
0 commit comments