Skip to content

Commit

Permalink
refactor 1
Browse files Browse the repository at this point in the history
  • Loading branch information
heesung-sn committed Nov 1, 2024
1 parent 170be11 commit ecfbca1
Show file tree
Hide file tree
Showing 16 changed files with 856 additions and 93 deletions.
16 changes: 16 additions & 0 deletions tests/integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,22 @@
<scope>test</scope>
</dependency>


<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
</dependency>
<dependency>
<groupId>org.apache.pulsar</groupId>
<artifactId>pulsar-client-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.pulsar</groupId>
<artifactId>pulsar-client-admin-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.tests.integration;

import org.apache.pulsar.client.admin.PulsarAdmin;
import org.apache.pulsar.client.api.PulsarClient;

public class IntegTest {
public PulsarClient client;
public PulsarAdmin admin;

public IntegTest(PulsarClient client, PulsarAdmin admin) {
this.client = client;
this.admin = admin;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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.tests.integration;

import static org.testng.Assert.assertTrue;
import java.util.concurrent.ThreadLocalRandom;
import lombok.extern.slf4j.Slf4j;
import org.apache.pulsar.client.admin.PulsarAdmin;

@Slf4j
public class IntegTestUtils {
private static String randomName(int numChars) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < numChars; i++) {
sb.append((char) (ThreadLocalRandom.current().nextInt(26) + 'a'));
}
return sb.toString();
}

protected static String generateNamespaceName() {
return "ns-" + randomName(8);
}

protected static String generateTopicName(String topicPrefix, boolean isPersistent) {
return generateTopicName("default", topicPrefix, isPersistent);
}

protected static String generateTopicName(String namespace, String topicPrefix, boolean isPersistent) {
String topicName = new StringBuilder(topicPrefix)
.append("-")
.append(randomName(8))
.append("-")
.append(System.currentTimeMillis())
.toString();
if (isPersistent) {
return "persistent://public/" + namespace + "/" + topicName;
} else {
return "non-persistent://public/" + namespace + "/" + topicName;
}
}

public static String getNonPartitionedTopic(PulsarAdmin admin, String topicPrefix, boolean isPersistent)
throws Exception {
String nsName = generateNamespaceName();
admin.namespaces().createNamespace("public/" + nsName);
return generateTopicName(nsName, topicPrefix, isPersistent);
}

public static String getPartitionedTopic(PulsarAdmin admin, String topicPrefix, boolean isPersistent,
int partitions) throws Exception {
assertTrue(partitions > 0, "partitions must greater than 1");
String nsName = generateNamespaceName();
admin.namespaces().createNamespace("public/" + nsName);
String topicName = generateTopicName(nsName, topicPrefix, isPersistent);
admin.topics().createPartitionedTopic(topicName, partitions);
return topicName;
}
}
Loading

0 comments on commit ecfbca1

Please sign in to comment.