forked from apache/pulsar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Keep topic-level policies commands consistent with that for namespace… (
apache#9215) Fixes apache#9205 ### Motivation In apache#9108, we add some topic-level policies commands, and found some commands are not consistent with that for namespace-level. For example, On namespace-level, the policies commands are: ``` get-max-producers set-max-producers remove-max-producers get-max-unacked-messages-per-subscription set-max-unacked-messages-per-subscription remove-max-unacked-messages-per-subscription ``` On topic-level, the polices commands are: ``` get-maxProducers set-maxProducers remove-maxProducers get-max-unacked-messages-on-subscription set-max-unacked-messages-on-subscription remove-max-unacked-messages-on-subscription ``` ### Modifications Keep topic-level policies commands consistent with that for namespace
- Loading branch information
Showing
5 changed files
with
275 additions
and
2 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
...-client-tools-test/src/test/java/org/apache/pulsar/admin/cli/DeprecatedCommanderTest.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,85 @@ | ||
/** | ||
* 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.admin.cli; | ||
|
||
|
||
import com.beust.jcommander.DefaultUsageFormatter; | ||
import org.apache.pulsar.client.admin.PulsarAdmin; | ||
import org.apache.pulsar.client.admin.Schemas; | ||
import org.apache.pulsar.client.admin.Topics; | ||
import org.mockito.Mockito; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertFalse; | ||
import static org.testng.Assert.assertNotEquals; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
public class DeprecatedCommanderTest { | ||
PulsarAdmin admin; | ||
Topics mockTopics; | ||
Schemas mockSchemas; | ||
CmdTopics cmdTopics; | ||
|
||
@BeforeMethod | ||
public void setup() { | ||
admin = Mockito.mock(PulsarAdmin.class); | ||
mockTopics = mock(Topics.class); | ||
when(admin.topics()).thenReturn(mockTopics); | ||
mockSchemas = mock(Schemas.class); | ||
when(admin.schemas()).thenReturn(mockSchemas); | ||
cmdTopics = new CmdTopics(admin); | ||
} | ||
|
||
@Test | ||
public void testDeprecatedCommanderWorks() throws Exception { | ||
|
||
DefaultUsageFormatter defaultUsageFormatter = new DefaultUsageFormatter(cmdTopics.jcommander); | ||
StringBuilder builder = new StringBuilder(); | ||
defaultUsageFormatter.usage(builder); | ||
String defaultOutput = builder.toString(); | ||
|
||
StringBuilder builder2 = new StringBuilder(); | ||
cmdTopics.jcommander.getUsageFormatter().usage(builder2); | ||
String outputWithFiltered = builder2.toString(); | ||
|
||
assertNotEquals(outputWithFiltered, defaultOutput); | ||
assertFalse(outputWithFiltered.contains("enable-deduplication")); | ||
assertTrue(defaultOutput.contains("enable-deduplication")); | ||
assertFalse(outputWithFiltered.contains("get-max-unacked-messages-on-consumer")); | ||
assertTrue(defaultOutput.contains("get-max-unacked-messages-on-consumer")); | ||
assertTrue(outputWithFiltered.contains("get-deduplication")); | ||
assertTrue(defaultOutput.contains("get-deduplication")); | ||
|
||
// annotation was changed to hidden, reset it. | ||
cmdTopics = new CmdTopics(admin); | ||
CmdUsageFormatter formatter = (CmdUsageFormatter)cmdTopics.jcommander.getUsageFormatter(); | ||
formatter.clearDeprecatedCommand(); | ||
StringBuilder builder3 = new StringBuilder(); | ||
cmdTopics.jcommander.getUsageFormatter().usage(builder3); | ||
String outputAfterClean = builder3.toString(); | ||
|
||
assertEquals(outputAfterClean, defaultOutput); | ||
|
||
} | ||
|
||
} |
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
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
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
Oops, something went wrong.