You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by si...@apache.org on 2018/08/02 20:24:58 UTC

[incubator-pulsar] branch master updated: add System property config to run real S3 and GCS test for offloader (#2281)

This is an automated email from the ASF dual-hosted git repository.

sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 8103fd1  add System property config to run real S3 and GCS test for offloader (#2281)
8103fd1 is described below

commit 8103fd17006cd6dfad91ca94e62ea47a62efd834
Author: Jia Zhai <ji...@users.noreply.github.com>
AuthorDate: Fri Aug 3 04:24:56 2018 +0800

    add System property config to run real S3 and GCS test for offloader (#2281)
    
    ### Motivation
    
    BlobStoreTestBase should support to use real AWS S3 and real GCS, if a system property was set.
    
    ### Modifications
    
    - change BlobStoreTestBase, add related System property config
    - fix error when run BlobStoreManagedLedgerOffloaderTest and BlobStoreBackedInputStreamTest
    
    ### Result
    
    Pass UT: BlobStoreBackedInputStreamTest and BlobStoreManagedLedgerOffloaderTest by using RealAWS and RealGCS
---
 .../pulsar/broker/offload/BlobStoreTestBase.java   | 37 ++++++++++++++++++----
 .../impl/BlobStoreManagedLedgerOffloaderTest.java  | 23 +++++++++-----
 2 files changed, 46 insertions(+), 14 deletions(-)

diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/offload/BlobStoreTestBase.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/offload/BlobStoreTestBase.java
index d1474f9..8e21c47 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/offload/BlobStoreTestBase.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/offload/BlobStoreTestBase.java
@@ -36,16 +36,41 @@ public class BlobStoreTestBase {
 
     @BeforeMethod
     public void start() throws Exception {
-        context = ContextBuilder.newBuilder("transient").build(BlobStoreContext.class);
-        blobStore = context.getBlobStore();
-        boolean create = blobStore.createContainerInLocation(null, BUCKET);
-
-        log.debug("TestBase Create Bucket: {}, in blobStore, result: {}", BUCKET, create);
+        if (Boolean.parseBoolean(System.getProperty("testRealAWS", "false"))) {
+            log.info("TestReal AWS S3, bucket: {}", BUCKET);
+            // To use this, must config credentials using "aws_access_key_id" as S3ID,
+            // and "aws_secret_access_key" as S3Key. And bucket should exist in default region. e.g.
+            //        props.setProperty("S3ID", "AXXXXXXQ");
+            //        props.setProperty("S3Key", "HXXXXXß");
+            context = ContextBuilder.newBuilder("aws-s3")
+                .credentials(System.getProperty("S3ID"), System.getProperty("S3Key"))
+                .build(BlobStoreContext.class);
+            blobStore = context.getBlobStore();
+            // To use this, ~/.aws must be configured with credentials and a default region
+            //s3client = AmazonS3ClientBuilder.standard().build();
+        } else if (Boolean.parseBoolean(System.getProperty("testRealGCS", "false"))) {
+            log.info("TestReal GCS, bucket: {}", BUCKET);
+            // To use this, must config credentials using "client_email" as GCSID and "private_key" as GCSKey.
+            // And bucket should exist in default region. e.g.
+            //        props.setProperty("GCSID", "5XXXXXXXXXX6-compute@developer.gserviceaccount.com");
+            //        props.setProperty("GCSKey", "XXXXXX");
+            context = ContextBuilder.newBuilder("google-cloud-storage")
+                .credentials(System.getProperty("GCSID"), System.getProperty("GCSKey"))
+                .build(BlobStoreContext.class);
+            blobStore = context.getBlobStore();
+        } else {
+            context = ContextBuilder.newBuilder("transient").build(BlobStoreContext.class);
+            blobStore = context.getBlobStore();
+            boolean create = blobStore.createContainerInLocation(null, BUCKET);
+            log.debug("TestBase Create Bucket: {}, in blobStore, result: {}", BUCKET, create);
+        }
     }
 
     @AfterMethod
     public void tearDown() {
-        if (blobStore != null) {
+        if (blobStore != null &&
+            (!Boolean.parseBoolean(System.getProperty("testRealGCS", "false")) &&
+             !Boolean.parseBoolean(System.getProperty("testRealGCS", "false")))) {
             blobStore.deleteContainer(BUCKET);
         }
 
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/offload/impl/BlobStoreManagedLedgerOffloaderTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/offload/impl/BlobStoreManagedLedgerOffloaderTest.java
index 86b4657..f1e43c2 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/offload/impl/BlobStoreManagedLedgerOffloaderTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/offload/impl/BlobStoreManagedLedgerOffloaderTest.java
@@ -59,6 +59,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.testng.Assert;
 import org.testng.annotations.Test;
+import org.testng.collections.Maps;
 
 @Slf4j
 class BlobStoreManagedLedgerOffloaderTest extends BlobStoreTestBase {
@@ -131,8 +132,8 @@ class BlobStoreManagedLedgerOffloaderTest extends BlobStoreTestBase {
             offloader.offload(buildReadHandle(), UUID.randomUUID(), new HashMap<>()).get();
             Assert.fail("Shouldn't be able to add to bucket");
         } catch (ExecutionException e) {
-            log.error("Exception: ", e.getMessage());
-            Assert.assertTrue(e.getMessage().contains("not found"));
+            log.error("Exception: ", e);
+            Assert.assertTrue(e.getMessage().toLowerCase().contains("not found"));
         }
     }
 
@@ -520,8 +521,11 @@ class BlobStoreManagedLedgerOffloaderTest extends BlobStoreTestBase {
 
         String dataKey = dataBlockOffloadKey(toWrite.getId(), uuid);
 
-        Map<String, String> userMeta = blobStore.blobMetadata(BUCKET, dataKey).getUserMetadata();
-        userMeta.put(BlobStoreManagedLedgerOffloader.METADATA_FORMAT_VERSION_KEY, String.valueOf(-12345));
+        // Here it will return a Immutable map.
+        Map<String, String> immutableMap = blobStore.blobMetadata(BUCKET, dataKey).getUserMetadata();
+        Map<String, String> userMeta = Maps.newHashMap();
+        userMeta.putAll(immutableMap);
+        userMeta.put(BlobStoreManagedLedgerOffloader.METADATA_FORMAT_VERSION_KEY.toLowerCase(), String.valueOf(-12345));
         blobStore.copyBlob(BUCKET, dataKey, BUCKET, dataKey, CopyOptions.builder().userMetadata(userMeta).build());
 
         try (ReadHandle toRead = offloader.readOffloaded(toWrite.getId(), uuid).get()) {
@@ -533,7 +537,7 @@ class BlobStoreManagedLedgerOffloaderTest extends BlobStoreTestBase {
             Assert.assertTrue(e.getCause().getMessage().contains("Error reading from BlobStore"));
         }
 
-        userMeta.put(BlobStoreManagedLedgerOffloader.METADATA_FORMAT_VERSION_KEY, String.valueOf(12345));
+        userMeta.put(BlobStoreManagedLedgerOffloader.METADATA_FORMAT_VERSION_KEY.toLowerCase(), String.valueOf(12345));
         blobStore.copyBlob(BUCKET, dataKey, BUCKET, dataKey, CopyOptions.builder().userMetadata(userMeta).build());
 
         try (ReadHandle toRead = offloader.readOffloaded(toWrite.getId(), uuid).get()) {
@@ -555,8 +559,11 @@ class BlobStoreManagedLedgerOffloaderTest extends BlobStoreTestBase {
 
         String indexKey = indexBlockOffloadKey(toWrite.getId(), uuid);
 
-        Map<String, String> userMeta = blobStore.blobMetadata(BUCKET, indexKey).getUserMetadata();
-        userMeta.put(BlobStoreManagedLedgerOffloader.METADATA_FORMAT_VERSION_KEY, String.valueOf(-12345));
+        // Here it will return a Immutable map.
+        Map<String, String> immutableMap = blobStore.blobMetadata(BUCKET, indexKey).getUserMetadata();
+        Map<String, String> userMeta = Maps.newHashMap();
+        userMeta.putAll(immutableMap);
+        userMeta.put(BlobStoreManagedLedgerOffloader.METADATA_FORMAT_VERSION_KEY.toLowerCase(), String.valueOf(-12345));
         blobStore.copyBlob(BUCKET, indexKey, BUCKET, indexKey, CopyOptions.builder().userMetadata(userMeta).build());
 
         try {
@@ -567,7 +574,7 @@ class BlobStoreManagedLedgerOffloaderTest extends BlobStoreTestBase {
             Assert.assertTrue(e.getCause().getMessage().contains("Invalid object version"));
         }
 
-        userMeta.put(BlobStoreManagedLedgerOffloader.METADATA_FORMAT_VERSION_KEY, String.valueOf(12345));
+        userMeta.put(BlobStoreManagedLedgerOffloader.METADATA_FORMAT_VERSION_KEY.toLowerCase(), String.valueOf(12345));
         blobStore.copyBlob(BUCKET, indexKey, BUCKET, indexKey, CopyOptions.builder().userMetadata(userMeta).build());
 
         try {