You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2019/05/18 16:50:08 UTC

[pulsar] branch master updated: Add operation to message of BkException (#4305)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 3c3efdc  Add operation to message of BkException (#4305)
3c3efdc is described below

commit 3c3efdc55122f0ff52a766a8b227a02c8b1ac7da
Author: Like <ke...@outlook.com>
AuthorDate: Sun May 19 00:50:01 2019 +0800

    Add operation to message of BkException (#4305)
    
    * Add operation to message of BkException
    
    * Add test
---
 .../service/schema/BookkeeperSchemaStorage.java    |  3 +-
 .../schema/BookkeeperSchemaStorageTest.java        | 44 ++++++++++++++++++++++
 2 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/schema/BookkeeperSchemaStorage.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/schema/BookkeeperSchemaStorage.java
index 47fcb62..82c7156 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/schema/BookkeeperSchemaStorage.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/schema/BookkeeperSchemaStorage.java
@@ -611,7 +611,8 @@ public class BookkeeperSchemaStorage implements SchemaStorage {
     }
 
     public static Exception bkException(String operation, int rc, long ledgerId, long entryId) {
-        String message = org.apache.bookkeeper.client.api.BKException.getMessage(rc) + " -  ledger=" + ledgerId;
+        String message = org.apache.bookkeeper.client.api.BKException.getMessage(rc)
+                + " -  ledger=" + ledgerId + " - operation=" + operation;
 
         if (entryId != -1) {
             message += " - entry=" + entryId;
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/schema/BookkeeperSchemaStorageTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/schema/BookkeeperSchemaStorageTest.java
new file mode 100644
index 0000000..5d7f9d1
--- /dev/null
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/schema/BookkeeperSchemaStorageTest.java
@@ -0,0 +1,44 @@
+/**
+ * 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.broker.service.schema;
+
+
+import org.apache.bookkeeper.client.api.BKException;
+import org.testng.annotations.Test;
+
+import static org.apache.pulsar.broker.service.schema.BookkeeperSchemaStorage.bkException;
+import static org.testng.Assert.assertEquals;
+
+public class BookkeeperSchemaStorageTest {
+
+    @Test
+    public void testBkException() {
+        Exception ex = bkException("test", BKException.Code.ReadException, 1, -1);
+        assertEquals("Error while reading ledger -  ledger=1 - operation=test", ex.getMessage());
+        ex = bkException("test", BKException.Code.ReadException, 1, 0);
+        assertEquals("Error while reading ledger -  ledger=1 - operation=test - entry=0",
+                ex.getMessage());
+        ex = bkException("test", BKException.Code.QuorumException, 1, -1);
+        assertEquals("Invalid quorum size on ensemble size -  ledger=1 - operation=test",
+                ex.getMessage());
+        ex = bkException("test", BKException.Code.QuorumException, 1, 0);
+        assertEquals("Invalid quorum size on ensemble size -  ledger=1 - operation=test - entry=0",
+                ex.getMessage());
+    }
+}