You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2018/05/01 02:18:56 UTC

[GitHub] zhaijack commented on a change in pull request #1593: PIP-17: the part of index block for offload.

zhaijack commented on a change in pull request #1593: PIP-17:  the part of index block for offload.
URL: https://github.com/apache/incubator-pulsar/pull/1593#discussion_r185156310
 
 

 ##########
 File path: pulsar-broker/src/test/java/org/apache/pulsar/s3offload/OffloadIndexTest.java
 ##########
 @@ -0,0 +1,196 @@
+/**
+ * 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.pulsar.s3offload;
+
+import static com.google.common.base.Charsets.UTF_8;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Map;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.bookkeeper.client.BookKeeper.DigestType;
+import org.apache.bookkeeper.client.api.LedgerMetadata;
+import org.apache.bookkeeper.net.BookieSocketAddress;
+import org.apache.pulsar.broker.s3offload.OffloadIndexBlock;
+import org.apache.pulsar.broker.s3offload.OffloadIndexBlockBuilder;
+import org.apache.pulsar.broker.s3offload.OffloadIndexEntry;
+import org.apache.pulsar.broker.s3offload.impl.OffloadIndexEntryImpl;
+import org.testng.annotations.Test;
+
+@Slf4j
+public class OffloadIndexTest {
+
+    @Test
+    public void offloadIndexEntryImplTest() {
+        // verify OffloadIndexEntryImpl builder
+        OffloadIndexEntryImpl entry1 = OffloadIndexEntryImpl.of(0, 2, 0);
+        OffloadIndexEntryImpl entry2 = OffloadIndexEntryImpl.of(100, 3, 1234);
+
+        // verify OffloadIndexEntryImpl get
+        assertTrue(entry1.getEntryId() == 0L);
+        assertTrue(entry1.getPartId() == 2);
+        assertTrue(entry1.getOffset() == 0L);
+
+        assertTrue(entry2.getEntryId() == 100L);
+        assertTrue(entry2.getPartId() == 3);
+        assertTrue(entry2.getOffset() == 1234L);
+    }
+
+
+    // use mock to setLastEntryId
+    class LedgerMetadataMock extends org.apache.bookkeeper.client.LedgerMetadata {
+        long lastId = 0;
+        public LedgerMetadataMock(int ensembleSize, int writeQuorumSize, int ackQuorumSize, org.apache.bookkeeper.client.BookKeeper.DigestType digestType, byte[] password, Map<String, byte[]> customMetadata, boolean storeSystemtimeAsLedgerCreationTime) {
+            super(ensembleSize, writeQuorumSize, ackQuorumSize, digestType, password, customMetadata, storeSystemtimeAsLedgerCreationTime);
+        }
+
+        @Override
+        public long getLastEntryId(){
+            return  lastId;
+        }
+
+        public void setLastEntryId(long lastId) {
+            this.lastId = lastId;
+        }
+    }
+
+    private LedgerMetadata createLedgerMetadata() throws Exception {
+
+        Map<String, byte[]> metadataCustom = Maps.newHashMap();
+        metadataCustom.put("key1", "value1".getBytes(UTF_8));
+        metadataCustom.put("key7", "value7".getBytes(UTF_8));
+
+        ArrayList<BookieSocketAddress> bookies = Lists.newArrayList();
+        BookieSocketAddress BOOKIE1 = new BookieSocketAddress("127.0.0.1:3181");
+        BookieSocketAddress BOOKIE2 = new BookieSocketAddress("127.0.0.2:3181");
+        BookieSocketAddress BOOKIE3 = new BookieSocketAddress("127.0.0.3:3181");
+        bookies.add(0, BOOKIE1);
+        bookies.add(1, BOOKIE2);
+        bookies.add(2, BOOKIE3);
+
+        LedgerMetadataMock metadata = new LedgerMetadataMock(3, 3, 2,
+            DigestType.CRC32C, "password".getBytes(UTF_8), metadataCustom, false);
+
+        metadata.addEnsemble(0, bookies);
+        metadata.setLastEntryId(5000);
+        return metadata;
+    }
+
+    // prepare metadata, then use builder to build a OffloadIndexBlockImpl
+    // verify get methods, readout and fromStream methods.
+    @Test
+    public void offloadIndexBlockImplTest() throws Exception {
+        OffloadIndexBlockBuilder blockBuilder = OffloadIndexBlockBuilder.create();
+        LedgerMetadata metadata = createLedgerMetadata();
+        log.debug("created metadata: {}", metadata.toString());
+
+        blockBuilder.withMetadata(metadata);
+
+        blockBuilder.addBlock(0, 2, 0);
+        blockBuilder.addBlock(1000, 3, 64 * 1024 * 1024);
+        blockBuilder.addBlock(2000, 4, 64 * 1024 * 1024);
+        OffloadIndexBlock indexBlock = blockBuilder.build();
+
+        // verify getEntryCount and getLedgerMetadata
+        assertTrue(indexBlock.getEntryCount() == 3);
+        assertTrue(indexBlock.getLedgerMetadata() == metadata);
 
 Review comment:
   Yes, it verify same object here.

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


With regards,
Apache Git Services