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

[ISSUE #3828] Code optimization for StandaloneAdminTest and TestUtils #4784

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.apache.eventmesh.storage.standalone.broker.model.TopicMetadata;

import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

Expand All @@ -35,8 +35,6 @@ public class TestUtils {
public static final int OFF_SET = 0;
public static final int LENGTH = 5;
public static final int EXCEEDED_MESSAGE_STORE_WINDOW = 60 * 60 * 1000 + 1000;
public static final boolean TOPIC_EXISTS = true;
public static final boolean TOPIC_DO_NOT_EXISTS = false;

public static ConcurrentHashMap<TopicMetadata, MessageQueue> createDefaultMessageContainer() {
ConcurrentHashMap<TopicMetadata, MessageQueue> messageContainer = new ConcurrentHashMap<>(1);
Expand All @@ -63,7 +61,7 @@ public static CloudEvent createDefaultCloudEvent() {
}

public static List<CloudEvent> createCloudEvents() {
return Arrays.asList(createDefaultCloudEvent());
return Collections.singletonList(createDefaultCloudEvent());
}

public static MessageEntity createDefaultMessageEntity() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
import static org.apache.eventmesh.storage.standalone.TestUtils.LENGTH;
import static org.apache.eventmesh.storage.standalone.TestUtils.OFF_SET;
import static org.apache.eventmesh.storage.standalone.TestUtils.TEST_TOPIC;
import static org.apache.eventmesh.storage.standalone.TestUtils.TOPIC_DO_NOT_EXISTS;
import static org.apache.eventmesh.storage.standalone.TestUtils.TOPIC_EXISTS;
import static org.apache.eventmesh.storage.standalone.TestUtils.createDefaultCloudEvent;
import static org.apache.eventmesh.storage.standalone.TestUtils.createDefaultMessageContainer;
import static org.apache.eventmesh.storage.standalone.TestUtils.createDefaultMessageEntity;

import org.apache.eventmesh.api.admin.TopicProperties;
import org.apache.eventmesh.storage.standalone.broker.StandaloneBroker;
import org.apache.eventmesh.storage.standalone.broker.model.MessageEntity;

Expand Down Expand Up @@ -72,8 +71,9 @@ public void testIsClosed() {

@Test
public void testGetTopic() throws Exception {
Assertions.assertNotNull(standaloneAdmin.getTopic());
Assertions.assertFalse(standaloneAdmin.getTopic().isEmpty());
List<TopicProperties> topicPropertiesList = standaloneAdmin.getTopic();
Assertions.assertNotNull(topicPropertiesList);
Assertions.assertFalse(topicPropertiesList.isEmpty());
}

@Test
Expand All @@ -90,7 +90,7 @@ public void testDeleteTopic() {

@Test
public void testGetEvent() throws Exception {
Mockito.when(standaloneBroker.checkTopicExist(TEST_TOPIC)).thenReturn(TOPIC_EXISTS);
Mockito.when(standaloneBroker.checkTopicExist(TEST_TOPIC)).thenReturn(Boolean.TRUE);
Mockito.when(standaloneBroker.getMessage(TEST_TOPIC, OFF_SET)).thenReturn(createDefaultCloudEvent());
Pil0tXia marked this conversation as resolved.
Show resolved Hide resolved
List<CloudEvent> events = standaloneAdmin.getEvent(TEST_TOPIC, OFF_SET, LENGTH);
Assertions.assertNotNull(events);
Expand All @@ -99,7 +99,7 @@ public void testGetEvent() throws Exception {

@Test
public void testGetEvent_throwException() {
Mockito.when(standaloneBroker.checkTopicExist(TEST_TOPIC)).thenReturn(TOPIC_DO_NOT_EXISTS);
Mockito.when(standaloneBroker.checkTopicExist(TEST_TOPIC)).thenReturn(Boolean.FALSE);
Exception exception = Assertions.assertThrows(Exception.class, () -> standaloneAdmin.getEvent(TEST_TOPIC, OFF_SET, LENGTH));
Assertions.assertEquals("The topic name doesn't exist in the message queue", exception.getMessage());
}
Expand Down
Loading