-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Broker] Fix NPE of internalExpireMessagesByTimestamp (#14243)
This issue was triggered by #13880, it doesn't handle the NPE in [here](https://github.com/apache/pulsar/pull/13880/files#diff-66aeb65a64cbe7c541f013ae807c5bcbeab567bef77706c7ff2e0cbfe0d77eb1R3502), we can check the [diff code](https://github.com/apache/pulsar/pull/13880/files#diff-66aeb65a64cbe7c541f013ae807c5bcbeab567bef77706c7ff2e0cbfe0d77eb1L3489) in #13880. (cherry picked from commit a3c8525)
- Loading branch information
Showing
3 changed files
with
98 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiSubscriptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* 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.admin; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.expectThrows; | ||
import javax.ws.rs.core.Response; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest; | ||
import org.apache.pulsar.client.admin.PulsarAdminException; | ||
import org.apache.pulsar.client.api.MessageId; | ||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
@Slf4j | ||
@Test(groups = "broker-admin") | ||
public class AdminApiSubscriptionTest extends MockedPulsarServiceBaseTest { | ||
@BeforeMethod | ||
@Override | ||
public void setup() throws Exception { | ||
super.internalSetup(); | ||
super.setupDefaultTenantAndNamespace(); | ||
} | ||
|
||
@AfterMethod(alwaysRun = true) | ||
@Override | ||
public void cleanup() throws Exception { | ||
super.internalCleanup(); | ||
} | ||
|
||
@Test | ||
public void testExpireNonExistTopic() throws Exception { | ||
String topic = "test-expire-messages-topic"; | ||
String subscriptionName = "test-expire-messages-sub"; | ||
admin.topics().createSubscription(topic, subscriptionName, MessageId.latest); | ||
assertEquals(expectThrows(PulsarAdminException.class, | ||
() -> admin.topics().expireMessages(topic, subscriptionName, 1)).getStatusCode(), | ||
Response.Status.CONFLICT.getStatusCode()); | ||
assertEquals(expectThrows(PulsarAdminException.class, | ||
() -> admin.topics().expireMessagesForAllSubscriptions(topic, 1)).getStatusCode(), | ||
Response.Status.CONFLICT.getStatusCode()); | ||
} | ||
|
||
@Test | ||
public void TestExpireNonExistTopicAndNonExistSub() { | ||
String topic = "test-expire-messages-topic"; | ||
String subscriptionName = "test-expire-messages-sub"; | ||
assertEquals(expectThrows(PulsarAdminException.class, | ||
() -> admin.topics().expireMessages(topic, subscriptionName, 1)).getStatusCode(), | ||
Response.Status.NOT_FOUND.getStatusCode()); | ||
assertEquals(expectThrows(PulsarAdminException.class, | ||
() -> admin.topics().expireMessagesForAllSubscriptions(topic, 1)).getStatusCode(), | ||
Response.Status.NOT_FOUND.getStatusCode()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters