This is an automated email from the ASF dual-hosted git repository.
penghui 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 8d34b0f3836 [flaky-test]Add information in ManagedLedgerBkTest to
determine the problem (#17441)
8d34b0f3836 is described below
commit 8d34b0f38365b71c8c486a7464f2cbd90dcd4472
Author: fengyubiao <[email protected]>
AuthorDate: Mon Sep 19 10:24:47 2022 +0800
[flaky-test]Add information in ManagedLedgerBkTest to determine the problem
(#17441)
---
.../mledger/impl/ManagedLedgerBkTest.java | 12 +++++---
.../mledger/util/ThrowableToStringUtil.java | 36 ++++++++++++++++++++++
2 files changed, 43 insertions(+), 5 deletions(-)
diff --git
a/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerBkTest.java
b/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerBkTest.java
index 9026c0f6ac4..3ad521eeb79 100644
---
a/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerBkTest.java
+++
b/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerBkTest.java
@@ -19,7 +19,6 @@
package org.apache.bookkeeper.mledger.impl;
import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
@@ -50,6 +49,7 @@ import org.apache.bookkeeper.mledger.ManagedLedgerFactory;
import org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig;
import org.apache.bookkeeper.mledger.Position;
import org.apache.bookkeeper.mledger.impl.cache.EntryCacheManager;
+import org.apache.bookkeeper.mledger.util.ThrowableToStringUtil;
import org.apache.bookkeeper.test.BookKeeperClusterTestCase;
import org.apache.pulsar.common.policies.data.PersistentOfflineTopicStats;
import org.testng.annotations.Test;
@@ -312,7 +312,7 @@ public class ManagedLedgerBkTest extends
BookKeeperClusterTestCase {
}
final CountDownLatch counter = new CountDownLatch(positions.size());
- final AtomicBoolean gotException = new AtomicBoolean(false);
+ final AtomicReference<Exception> gotException = new AtomicReference();
for (Position p : positions) {
cursor.asyncDelete(p, new DeleteCallback() {
@@ -324,8 +324,7 @@ public class ManagedLedgerBkTest extends
BookKeeperClusterTestCase {
@Override
public void deleteFailed(ManagedLedgerException exception,
Object ctx) {
- exception.printStackTrace();
- gotException.set(true);
+ gotException.set(exception);
counter.countDown();
}
}, null);
@@ -336,7 +335,10 @@ public class ManagedLedgerBkTest extends
BookKeeperClusterTestCase {
cursor.close();
ledger.close();
- assertFalse(gotException.get());
+ // Add information to determine the problem.
+ if (gotException.get() != null){
+ fail(ThrowableToStringUtil.toString(gotException.get()));
+ }
}
/**
diff --git
a/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/util/ThrowableToStringUtil.java
b/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/util/ThrowableToStringUtil.java
new file mode 100644
index 00000000000..d7540ad30ca
--- /dev/null
+++
b/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/util/ThrowableToStringUtil.java
@@ -0,0 +1,36 @@
+/**
+ * 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.mledger.util;
+
+import org.apache.pulsar.common.util.FutureUtil;
+
+public class ThrowableToStringUtil {
+
+ public static String toString(Throwable throwable){
+ Throwable unwrapThrowable =
FutureUtil.unwrapCompletionException(throwable);
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append(unwrapThrowable.getClass().getName())
+ .append(": ").append(unwrapThrowable.getMessage());
+ for (StackTraceElement stackTraceElement :
unwrapThrowable.getStackTrace()){
+ stringBuilder.append(" at: ");
+ stringBuilder.append(stackTraceElement.toString());
+ }
+ return stringBuilder.toString();
+ }
+}