Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix flaky test in AdminApiOffloadTest #11028

Conversation

hangc0276
Copy link
Contributor

Motivation

Fix flaky test in AdminApiOffloadTest.
When namespace level offload policy and topic level offload policy both not set, the offloadPolicies filed will be null.

managedLedgerConfig.setLedgerOffloader(pulsar.getManagedLedgerOffloader(namespace, offloadPolicies));
public LedgerOffloader getManagedLedgerOffloader(NamespaceName namespaceName, OffloadPoliciesImpl offloadPolicies) {
        if (offloadPolicies == null) {
            return getDefaultOffloader();
        }
        return ledgerOffloaderMap.compute(namespaceName, (ns, offloader) -> {
            try {
                if (offloader != null && Objects.equals(offloader.getOffloadPolicies(), offloadPolicies)) {
                    return offloader;
                } else {
                    if (offloader != null) {
                        offloader.close();
                    }
                    return createManagedLedgerOffloader(offloadPolicies);
                }
            } catch (PulsarServerException e) {
                LOG.error("create ledgerOffloader failed for namespace {}", namespaceName.toString(), e);
                return new NullLedgerOffloader();
            }
        });
    }

Then in getManagedLedgerOffloader method, it will return getDefaultOffloader. And the test will get the following exception.

[ERROR] testTopicLevelOffloadNonPartitioned(org.apache.pulsar.broker.admin.AdminApiOffloadTest)  Time elapsed: 0.569 s  <<< FAILURE!
java.lang.AssertionError: expected [s3] but found [NullLedgerOffloader]
	at org.testng.Assert.fail(Assert.java:99)
	at org.testng.Assert.failNotEquals(Assert.java:1037)
	at org.testng.Assert.assertEqualsImpl(Assert.java:140)
	at org.testng.Assert.assertEquals(Assert.java:122)
	at org.testng.Assert.assertEquals(Assert.java:629)
	at org.testng.Assert.assertEquals(Assert.java:639)
	at org.apache.pulsar.broker.admin.AdminApiOffloadTest.testOffload(AdminApiOffloadTest.java:360)
	at org.apache.pulsar.broker.admin.AdminApiOffloadTest.testTopicLevelOffloadNonPartitioned(AdminApiOffloadTest.java:267)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132)
	at org.testng.internal.InvokeMethodRunnable.runOne(InvokeMethodRunnable.java:45)
	at org.testng.internal.InvokeMethodRunnable.call(InvokeMethodRunnable.java:73)
	at org.testng.internal.InvokeMethodRunnable.call(InvokeMethodRunnable.java:11)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

Modification

  1. Add doReturn inspection for offloadPolicies is null.

@315157973
Copy link
Contributor

Why doesn't it appear every time?

@hangc0276
Copy link
Contributor Author

Why doesn't it appear every time?

@315157973 because in current topic offload policy implementation, it doesn't refresh managedLedger configuration when topic offload policy updated, such as remote topic offload policy. When i fix the topic policy listener in #11021 , the test failed.

@merlimat merlimat added this to the 2.9.0 milestone Jun 23, 2021
@eolivelli eolivelli merged commit 1a80429 into apache:master Jun 23, 2021
kaushik-develop pushed a commit to kaushik-develop/pulsar that referenced this pull request Jun 24, 2021
hangc0276 added a commit that referenced this pull request Aug 12, 2021
@hangc0276 hangc0276 added the cherry-picked/branch-2.8 Archived: 2.8 is end of life label Aug 12, 2021
codelipenghui pushed a commit that referenced this pull request Dec 11, 2021
@codelipenghui codelipenghui added the cherry-picked/branch-2.7 Archived: 2.7 is end of life label Dec 11, 2021
bharanic-dev pushed a commit to bharanic-dev/pulsar that referenced this pull request Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants