Skip to content

Commit

Permalink
Add operation to message of BkException (apache#4305)
Browse files Browse the repository at this point in the history
* Add operation to message of BkException

* Add test
  • Loading branch information
liketic authored and merlimat committed May 18, 2019
1 parent 91d4495 commit 3c3efdc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,8 @@ static class LocatorEntry {
}

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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit 3c3efdc

Please sign in to comment.