rocketmq-dashboard-1.0.0.zip
立即下载
资源介绍:
rocketmq-dashboard-1.0.0.zip
/*
* 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.rocketmq.dashboard.admin;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.apache.rocketmq.client.QueryResult;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.impl.MQAdminImpl;
import org.apache.rocketmq.client.impl.MQClientAPIImpl;
import org.apache.rocketmq.client.impl.factory.MQClientInstance;
import org.apache.rocketmq.common.PlainAccessConfig;
import org.apache.rocketmq.common.TopicConfig;
import org.apache.rocketmq.common.admin.ConsumeStats;
import org.apache.rocketmq.common.admin.RollbackStats;
import org.apache.rocketmq.common.admin.TopicStatsTable;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.common.message.MessageQueue;
import org.apache.rocketmq.common.protocol.ResponseCode;
import org.apache.rocketmq.common.protocol.body.BrokerStatsData;
import org.apache.rocketmq.common.protocol.body.ClusterInfo;
import org.apache.rocketmq.common.protocol.body.ConsumeMessageDirectlyResult;
import org.apache.rocketmq.common.protocol.body.ConsumeStatsList;
import org.apache.rocketmq.common.protocol.body.ConsumerConnection;
import org.apache.rocketmq.common.protocol.body.ConsumerRunningInfo;
import org.apache.rocketmq.common.protocol.body.GroupList;
import org.apache.rocketmq.common.protocol.body.KVTable;
import org.apache.rocketmq.common.protocol.body.ProducerConnection;
import org.apache.rocketmq.common.protocol.body.QueueTimeSpan;
import org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper;
import org.apache.rocketmq.common.protocol.body.TopicConfigSerializeWrapper;
import org.apache.rocketmq.common.protocol.body.TopicList;
import org.apache.rocketmq.common.protocol.route.TopicRouteData;
import org.apache.rocketmq.common.subscription.SubscriptionGroupConfig;
import org.apache.rocketmq.dashboard.service.client.MQAdminExtImpl;
import org.apache.rocketmq.dashboard.service.client.MQAdminInstance;
import org.apache.rocketmq.dashboard.util.MockObjectUtil;
import org.apache.rocketmq.remoting.RemotingClient;
import org.apache.rocketmq.remoting.protocol.RemotingCommand;
import org.apache.rocketmq.remoting.protocol.RemotingSerializable;
import org.apache.rocketmq.store.stats.BrokerStatsManager;
import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
import org.apache.rocketmq.tools.admin.DefaultMQAdminExtImpl;
import org.apache.rocketmq.tools.admin.api.MessageTrack;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.Silent.class)
public class MQAdminExtImplTest {
@InjectMocks
private MQAdminExtImpl mqAdminExtImpl;
@Mock
private DefaultMQAdminExt defaultMQAdminExt;
@Mock
private DefaultMQAdminExtImpl defaultMQAdminExtImpl;
@Mock
private MQClientInstance mqClientInstance;
@Mock
private MQClientAPIImpl mQClientAPIImpl;
@Mock
private RemotingClient remotingClient;
private String brokerAddr = "127.0.0.1:10911";
@Before
public void init() throws Exception {
Field field = MQAdminInstance.class.getDeclaredField("MQ_ADMIN_EXT_THREAD_LOCAL");
field.setAccessible(true);
Object object = field.get(mqAdminExtImpl);
assertNotNull(object);
ThreadLocal threadLocal = (ThreadLocal) object;
defaultMQAdminExt = mock(DefaultMQAdminExt.class);
threadLocal.set(defaultMQAdminExt);
ReflectionTestUtils.setField(defaultMQAdminExt, "defaultMQAdminExtImpl", defaultMQAdminExtImpl);
ReflectionTestUtils.setField(defaultMQAdminExtImpl, "mqClientInstance", mqClientInstance);
ReflectionTestUtils.setField(mqClientInstance, "mQClientAPIImpl", mQClientAPIImpl);
ReflectionTestUtils.setField(mQClientAPIImpl, "remotingClient", remotingClient);
}
@Test
public void testUpdateBrokerConfig() throws Exception {
assertNotNull(mqAdminExtImpl);
doNothing()
.doThrow(new MQBrokerException(0, ""))
.when(defaultMQAdminExt).updateBrokerConfig(anyString(), any());
mqAdminExtImpl.updateBrokerConfig(brokerAddr, new Properties());
boolean hasException = false;
try {
mqAdminExtImpl.updateBrokerConfig(brokerAddr, new Properties());
} catch (Exception e) {
hasException = true;
assertThat(e).isInstanceOf(MQBrokerException.class);
assertThat(((MQBrokerException) e).getResponseCode()).isEqualTo(0);
}
assertTrue(hasException);
}
@Test
public void testCreateAndUpdateTopicConfig() throws Exception {
assertNotNull(mqAdminExtImpl);
mqAdminExtImpl.createAndUpdateTopicConfig(brokerAddr, new TopicConfig());
}
@Test
public void testDeletePlainAccessConfig() throws Exception {
assertNotNull(mqAdminExtImpl);
mqAdminExtImpl.deletePlainAccessConfig(brokerAddr, "rocketmq");
}
@Test
public void testUpdateGlobalWhiteAddrConfig() throws Exception {
assertNotNull(mqAdminExtImpl);
mqAdminExtImpl.updateGlobalWhiteAddrConfig(brokerAddr, "192.168.*.*");
}
@Test
public void testCreateAndUpdatePlainAccessConfig() throws Exception {
assertNotNull(mqAdminExtImpl);
mqAdminExtImpl.createAndUpdatePlainAccessConfig(brokerAddr, new PlainAccessConfig());
}
@Test
public void testExamineBrokerClusterAclVersionInfo() throws Exception {
assertNotNull(mqAdminExtImpl);
assertNull(mqAdminExtImpl.examineBrokerClusterAclVersionInfo(brokerAddr));
}
@Test
public void testExamineBrokerClusterAclConfig() throws Exception {
assertNotNull(mqAdminExtImpl);
assertNull(mqAdminExtImpl.examineBrokerClusterAclConfig(brokerAddr));
}
@Test
public void testQueryConsumerStatus() throws Exception {
assertNotNull(mqAdminExtImpl);
}
@Test
public void testCreateAndUpdateSubscriptionGroupConfig() throws Exception {
assertNotNull(mqAdminExtImpl);
mqAdminExtImpl.createAndUpdateSubscriptionGroupConfig(brokerAddr, new SubscriptionGroupConfig());
}
@Test
public void tes
资源文件列表:
rocketmq-dashboard-1.0.0.zip 大约有2414个文件