eolivelli commented on a change in pull request #1035: Ledgers without 
masterkey in metadata can't be recovered
URL: https://github.com/apache/bookkeeper/pull/1035#discussion_r163085664
 
 

 ##########
 File path: 
tests/backward-compat-recovery-no-password/src/test/groovy/org/apache/bookkeeper/tests/TestCompatRecoveryNoPassword.groovy
 ##########
 @@ -0,0 +1,248 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.bookkeeper.tests
+
+import com.github.dockerjava.api.DockerClient
+
+import io.netty.buffer.ByteBuf
+import java.util.ArrayList
+import java.util.HashMap
+import java.util.concurrent.CompletableFuture
+import java.util.concurrent.CountDownLatch
+import java.util.concurrent.TimeUnit
+import java.util.concurrent.atomic.AtomicLong
+
+import org.apache.bookkeeper.client.BKException
+import org.apache.bookkeeper.client.BookKeeper
+import org.apache.bookkeeper.client.BookKeeperAdmin
+import org.apache.bookkeeper.client.LedgerHandle
+import org.apache.bookkeeper.client.LedgerMetadata
+import org.apache.bookkeeper.conf.ClientConfiguration
+import org.apache.bookkeeper.net.BookieSocketAddress
+import 
org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.ReadEntryCallback
+
+import org.jboss.arquillian.junit.Arquillian
+import org.jboss.arquillian.test.api.ArquillianResource
+
+import org.junit.Assert
+import org.junit.Test
+import org.junit.runner.RunWith
+
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+
+@RunWith(Arquillian.class)
+class TestCompatRecoveryNoPassword {
+    private static final Logger LOG = 
LoggerFactory.getLogger(TestCompatRecoveryNoPassword.class)
+    private static byte[] PASSWD = "foobar".getBytes()
+
+    @ArquillianResource
+    DockerClient docker
+
+    private LedgerMetadata getLedgerMetadata(BookKeeper bookkeeper, long 
ledgerId) throws Exception {
+        CompletableFuture<LedgerMetadata> future = new 
CompletableFuture<LedgerMetadata>()
+        bookkeeper.getLedgerManager().readLedgerMetadata(
+            ledgerId, { rc, result ->
+                if (rc != BKException.Code.OK) {
+                    future.completeExceptionally(BKException.create(rc))
+                } else {
+                    future.complete(result)
+                }
+            })
+        return future.get()
+    }
+
+    private static class ReplicationVerificationCallback implements 
ReadEntryCallback {
+        final CountDownLatch latch;
+        final AtomicLong numSuccess;
+
+        ReplicationVerificationCallback(int numRequests) {
+            latch = new CountDownLatch(numRequests)
+            numSuccess = new AtomicLong(0)
+        }
+
+        @Override
+        public void readEntryComplete(int rc, long ledgerId, long entryId,
+                                      ByteBuf buffer, Object ctx) {
+            LOG.debug("Got {} for ledger {} entry {} from {}", rc, ledgerId, 
entryId, ctx)
+            if (rc == BKException.Code.OK) {
+                numSuccess.incrementAndGet()
+            }
+            latch.countDown()
+        }
+
+        long await() throws InterruptedException {
+            if (!latch.await(60, TimeUnit.SECONDS)) {
+                LOG.warn("Didn't get all responses in verification");
+                return 0;
+            } else {
+                return numSuccess.get();
+            }
+        }
+    }
+
+    private boolean verifyFullyReplicated(BookKeeper bookkeeper,
+                                          LedgerHandle lh,
+                                          long untilEntry) throws Exception {
+        LedgerMetadata md = getLedgerMetadata(bookkeeper, lh.getId())
+
+        def ensembles = md.getEnsembles()
+
+        def ranges = new HashMap<Long, Long>()
+        def keyList = new ArrayList(ensembles.keySet())
+        Collections.sort(keyList)
+        for (int i = 0; i < keyList.size() - 1; i++) {
+            ranges.put(keyList.get(i), keyList.get(i + 1))
+        }
+        ranges.put(keyList.get(keyList.size() - 1), untilEntry)
+
+        for (def e : ensembles.entrySet()) {
+            int quorum = md.getAckQuorumSize()
+            long startEntryId = e.getKey()
+            long endEntryId = ranges.get(startEntryId)
+            long expectedSuccess = quorum * (endEntryId - startEntryId)
+            int numRequests = e.getValue().size() * ((int) (endEntryId - 
startEntryId))
+
+            def cb = new ReplicationVerificationCallback(numRequests)
+            for (long i = startEntryId; i < endEntryId; i++) {
+                for (BookieSocketAddress addr : e.getValue()) {
+                    bookkeeper.getBookieClient()
+                        .readEntry(addr, lh.getId(), i, cb, addr)
+                }
+            }
+
+            long numSuccess = cb.await();
+            if (numSuccess < expectedSuccess) {
+                LOG.warn("Fragment not fully replicated ledgerId = {} 
startEntryId = {}"
+                         + " endEntryId = {} expectedSuccess = {} gotSuccess = 
{}",
+                         lh.getId(), startEntryId, endEntryId, 
expectedSuccess, numSuccess);
+                return false;
+            }
+        }
+        return true;
+    }
+
+    /**
+     * Test that when we try to recover a ledger which doesn't have
+     * the password stored in the configuration, we don't succeed.
+     */
+    @Test
+    public void testRecoveryWithoutPasswordInMetadata() throws Exception {
+        int numEntries = 10
+        byte[] passwdCorrect = "AAAAAA".getBytes()
+        byte[] passwdBad = "BBBBBB".getBytes()
+
+        String currentVersion = System.getProperty("currentVersion")
+        String zookeeper = 
BookKeeperClusterUtils.zookeeperConnectString(docker)
+
+        BookKeeperClusterUtils.legacyMetadataFormat(docker)
+
+        // Create a 4.1.0 client, will update /ledgers/LAYOUT
+        def v410CL = MavenClassLoader.forBookKeeperVersion("4.1.0")
 
 Review comment:
   I think we should try to close all classloaders
   
   If I undersand correctly we are using forkCount = 0, so no new JVM will be 
spawned for test.
   We should take care of not leaving memory (classloader) leaks 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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

Reply via email to