You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2019/03/16 05:16:25 UTC

[GitHub] [bookkeeper] zymap commented on a change in pull request #1988: Issue #1987: Migrate command `convert-to-interleaved-storage`

zymap commented on a change in pull request #1988: Issue #1987: Migrate command `convert-to-interleaved-storage`
URL: https://github.com/apache/bookkeeper/pull/1988#discussion_r266189592
 
 

 ##########
 File path: tools/ledger/src/test/java/org/apache/bookkeeper/tools/cli/commands/bookie/ConvertToInterleavedStorageCommandTest.java
 ##########
 @@ -0,0 +1,127 @@
+/*
+ * 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.tools.cli.commands.bookie;
+
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.powermock.api.mockito.PowerMockito.doNothing;
+import static org.powermock.api.mockito.PowerMockito.mock;
+import static org.powermock.api.mockito.PowerMockito.when;
+import static org.powermock.api.mockito.PowerMockito.whenNew;
+
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import java.io.File;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Vector;
+import java.util.stream.LongStream;
+import org.apache.bookkeeper.bookie.InterleavedLedgerStorage;
+import org.apache.bookkeeper.bookie.LedgerCache;
+import org.apache.bookkeeper.bookie.LedgerDirsManager;
+import org.apache.bookkeeper.bookie.storage.ldb.DbLedgerStorage;
+import org.apache.bookkeeper.conf.AbstractConfiguration;
+import org.apache.bookkeeper.conf.ServerConfiguration;
+import org.apache.bookkeeper.tools.cli.helpers.BookieCommandTestBase;
+import org.apache.bookkeeper.util.DiskChecker;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.junit.runner.RunWith;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+/**
+ * Unit test for {@link ConvertToInterleavedStorageCommand}.
+ */
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ ConvertToInterleavedStorageCommand.class, LedgerCache.class })
+public class ConvertToInterleavedStorageCommandTest extends BookieCommandTestBase {
+
+    @Rule
+    private TemporaryFolder folder = new TemporaryFolder();
+
+    public ConvertToInterleavedStorageCommandTest() {
+        super(3, 0);
+    }
+
+    @Override
+    public void setup() throws Exception {
+        super.setup();
+
+        createTmpFile();
+        PowerMockito.whenNew(ServerConfiguration.class).withNoArguments().thenReturn(conf);
+        PowerMockito.whenNew(ServerConfiguration.class).withParameterTypes(AbstractConfiguration.class)
+            .withArguments(eq(conf)).thenReturn(conf);
+
+        DiskChecker diskChecker = mock(DiskChecker.class);
+        whenNew(DiskChecker.class).withArguments(conf.getDiskUsageThreshold(), conf.getDiskUsageWarnThreshold())
+            .thenReturn(diskChecker);
+
+        LedgerDirsManager ledgerDirsManager = mock(LedgerDirsManager.class);
+        whenNew(LedgerDirsManager.class).withParameterTypes(ServerConfiguration.class, File[].class, DiskChecker.class)
+            .withArguments(conf, conf.getLedgerDirs(), diskChecker).thenReturn(ledgerDirsManager);
+        when(ledgerDirsManager.getAllLedgerDirs()).thenReturn(getFileList());
+
+        DbLedgerStorage dbStorage = mock(DbLedgerStorage.class);
+        whenNew(DbLedgerStorage.class).withNoArguments().thenReturn(dbStorage);
+        when(dbStorage.getActiveLedgersInRange(anyLong(), anyLong())).thenReturn(this::getLedgerId);
+
+        LedgerCache interleavedLedgerCache = mock(LedgerCache.class);
+        doNothing().when(interleavedLedgerCache).flushLedger(anyBoolean());
+
+        InterleavedLedgerStorage interleavedLedgerStorage = mock(InterleavedLedgerStorage.class);
+        whenNew(InterleavedLedgerStorage.class).withNoArguments().thenReturn(interleavedLedgerStorage);
+        doNothing().when(interleavedLedgerStorage).flush();
+        doNothing().when(interleavedLedgerStorage).shutdown();
+        when(interleavedLedgerStorage.getLedgerCache()).thenReturn(interleavedLedgerCache);
+    }
+
+    private Iterator<Long> getLedgerId() {
+        Vector<Long> longs = new Vector<>();
+        LongStream.range(0L, 10L).forEach(longs::add);
+        return longs.iterator();
+    }
+
+    private List<File> getFileList() {
+        List<File> files = new LinkedList<>();
+        files.add(folder.getRoot());
+        return files;
+    }
+
+    private void createTmpFile() {
+        try {
+            folder.newFile("ledgers");
+            folder.newFile("locations");
+            System.out.println(folder.getRoot().getAbsolutePath());
+        } catch (IOException e) {
+            throw new UncheckedExecutionException(e.getMessage(), e);
+        }
+    }
+
+    @Test
+    public void testConvertToInterleavedStorageCommand() {
+        ConvertToInterleavedStorageCommand cmd = new ConvertToInterleavedStorageCommand();
+        Assert.assertTrue(cmd.apply(bkFlags, new String[] { "" }));
 
 Review comment:
   ok, i fix it. PTAL

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services