Merge pull request #1238 from jifengnan/develop
[ISSUE #1227] DomainsManagerTest and RaftStoreTest Don't Work
This commit is contained in:
commit
bceba36372
@ -17,47 +17,52 @@ package com.alibaba.nacos.naming.core;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.naming.BaseTest;
|
||||
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||
import com.alibaba.nacos.naming.consistency.ephemeral.distro.DistroConsistencyServiceImpl;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nkorange
|
||||
* @author jifengnan 2019-05-18
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = MockServletContext.class)
|
||||
@WebAppConfiguration
|
||||
public class DomainsManagerTest extends BaseTest {
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
super.before();
|
||||
serviceManager = new ServiceManager();
|
||||
}
|
||||
@Spy
|
||||
@InjectMocks
|
||||
private ServiceManager manager;
|
||||
|
||||
@Mock
|
||||
private DistroConsistencyServiceImpl consistencyService;
|
||||
|
||||
@Test
|
||||
public void easyRemoveDom() throws Exception {
|
||||
serviceManager.easyRemoveService(Constants.DEFAULT_NAMESPACE_ID, "nacos.test.1");
|
||||
Service service = new Service(TEST_SERVICE_NAME);
|
||||
service.setNamespaceId(TEST_NAMESPACE);
|
||||
manager.putService(service);
|
||||
manager.easyRemoveService(TEST_NAMESPACE, TEST_SERVICE_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void searchDom() throws Exception {
|
||||
Service service = new Service();
|
||||
service.setName("nacos.test.1");
|
||||
public void easyRemoveDomNotExist() throws Exception {
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
expectedException.expectMessage("specified service not exist, serviceName : " + TEST_SERVICE_NAME);
|
||||
manager.easyRemoveService(Constants.DEFAULT_NAMESPACE_ID, TEST_SERVICE_NAME);
|
||||
}
|
||||
|
||||
serviceManager.chooseServiceMap(Constants.DEFAULT_NAMESPACE_ID).put("nacos.test.1", service);
|
||||
@Test
|
||||
public void searchDom() {
|
||||
Service service = new Service(TEST_SERVICE_NAME);
|
||||
service.setNamespaceId(TEST_NAMESPACE);
|
||||
manager.putService(service);
|
||||
|
||||
List<Service> list = serviceManager.searchServices(Constants.DEFAULT_NAMESPACE_ID, "nacos.test.*");
|
||||
List<Service> list = manager.searchServices(TEST_NAMESPACE, "test.*");
|
||||
Assert.assertNotNull(list);
|
||||
Assert.assertEquals(1, list.size());
|
||||
Assert.assertEquals("nacos.test.1", list.get(0).getName());
|
||||
Assert.assertEquals(TEST_SERVICE_NAME, list.get(0).getName());
|
||||
}
|
||||
}
|
||||
|
@ -15,39 +15,49 @@
|
||||
*/
|
||||
package com.alibaba.nacos.naming.raft;
|
||||
|
||||
import com.alibaba.nacos.naming.BaseTest;
|
||||
import com.alibaba.nacos.naming.consistency.Datum;
|
||||
import com.alibaba.nacos.naming.consistency.KeyBuilder;
|
||||
import com.alibaba.nacos.naming.consistency.persistent.raft.RaftCore;
|
||||
import com.alibaba.nacos.naming.consistency.persistent.raft.RaftStore;
|
||||
import com.alibaba.nacos.naming.core.Instance;
|
||||
import com.alibaba.nacos.naming.core.Instances;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Spy;
|
||||
|
||||
/**
|
||||
* @author nkorange
|
||||
* @author jifengnan 2019-05-18
|
||||
*/
|
||||
public class RaftStoreTest {
|
||||
public class RaftStoreTest extends BaseTest {
|
||||
|
||||
@Mock
|
||||
@InjectMocks
|
||||
@Spy
|
||||
public RaftCore raftCore;
|
||||
|
||||
@Mock
|
||||
@Spy
|
||||
public RaftStore raftStore;
|
||||
|
||||
@Test
|
||||
public void wrietDatum() throws Exception {
|
||||
|
||||
Datum datum = new Datum();
|
||||
datum.key = "1.2.3.4";
|
||||
Datum<Instances> datum = new Datum<>();
|
||||
String key = KeyBuilder.buildInstanceListKey(TEST_NAMESPACE, TEST_SERVICE_NAME, false);
|
||||
datum.key = key;
|
||||
datum.timestamp.getAndIncrement();
|
||||
datum.value = new Instances();
|
||||
Instance instance = new Instance("1.1.1.1", 1, TEST_CLUSTER_NAME);
|
||||
datum.value.getInstanceList().add(instance);
|
||||
instance = new Instance("2.2.2.2", 2, TEST_CLUSTER_NAME);
|
||||
datum.value.getInstanceList().add(instance);
|
||||
|
||||
raftStore.write(datum);
|
||||
raftCore.init();
|
||||
Datum result = raftCore.getDatum(key);
|
||||
|
||||
raftCore.loadDatum("1.2.3.4");
|
||||
|
||||
Datum result = raftCore.getDatum("1.2.3.4");
|
||||
|
||||
Assert.assertNotNull(result);
|
||||
Assert.assertEquals("value1", result.value);
|
||||
Assert.assertEquals(key, result.key);
|
||||
Assert.assertEquals(1, result.timestamp.intValue());
|
||||
Assert.assertEquals(datum.value.toString(), result.value.toString());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user