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.api.common.Constants;
|
||||||
import com.alibaba.nacos.naming.BaseTest;
|
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.Assert;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.mockito.InjectMocks;
|
||||||
import org.springframework.mock.web.MockServletContext;
|
import org.mockito.Mock;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.mockito.Spy;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
import org.springframework.test.context.web.WebAppConfiguration;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author nkorange
|
* @author nkorange
|
||||||
|
* @author jifengnan 2019-05-18
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@ContextConfiguration(classes = MockServletContext.class)
|
|
||||||
@WebAppConfiguration
|
|
||||||
public class DomainsManagerTest extends BaseTest {
|
public class DomainsManagerTest extends BaseTest {
|
||||||
|
|
||||||
@Before
|
@Spy
|
||||||
public void before() {
|
@InjectMocks
|
||||||
super.before();
|
private ServiceManager manager;
|
||||||
serviceManager = new ServiceManager();
|
|
||||||
}
|
@Mock
|
||||||
|
private DistroConsistencyServiceImpl consistencyService;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void easyRemoveDom() throws Exception {
|
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
|
@Test
|
||||||
public void searchDom() throws Exception {
|
public void easyRemoveDomNotExist() throws Exception {
|
||||||
Service service = new Service();
|
expectedException.expect(IllegalArgumentException.class);
|
||||||
service.setName("nacos.test.1");
|
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.assertNotNull(list);
|
||||||
Assert.assertEquals(1, list.size());
|
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;
|
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.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.RaftCore;
|
||||||
import com.alibaba.nacos.naming.consistency.persistent.raft.RaftStore;
|
import com.alibaba.nacos.naming.consistency.persistent.raft.RaftStore;
|
||||||
|
import com.alibaba.nacos.naming.core.Instance;
|
||||||
import com.alibaba.nacos.naming.core.Instances;
|
import com.alibaba.nacos.naming.core.Instances;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mock;
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Spy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author nkorange
|
* @author nkorange
|
||||||
|
* @author jifengnan 2019-05-18
|
||||||
*/
|
*/
|
||||||
public class RaftStoreTest {
|
public class RaftStoreTest extends BaseTest {
|
||||||
|
|
||||||
@Mock
|
@InjectMocks
|
||||||
|
@Spy
|
||||||
public RaftCore raftCore;
|
public RaftCore raftCore;
|
||||||
|
|
||||||
@Mock
|
@Spy
|
||||||
public RaftStore raftStore;
|
public RaftStore raftStore;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void wrietDatum() throws Exception {
|
public void wrietDatum() throws Exception {
|
||||||
|
Datum<Instances> datum = new Datum<>();
|
||||||
Datum datum = new Datum();
|
String key = KeyBuilder.buildInstanceListKey(TEST_NAMESPACE, TEST_SERVICE_NAME, false);
|
||||||
datum.key = "1.2.3.4";
|
datum.key = key;
|
||||||
|
datum.timestamp.getAndIncrement();
|
||||||
datum.value = new Instances();
|
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);
|
raftStore.write(datum);
|
||||||
|
raftCore.init();
|
||||||
|
Datum result = raftCore.getDatum(key);
|
||||||
|
|
||||||
raftCore.loadDatum("1.2.3.4");
|
Assert.assertEquals(key, result.key);
|
||||||
|
Assert.assertEquals(1, result.timestamp.intValue());
|
||||||
Datum result = raftCore.getDatum("1.2.3.4");
|
Assert.assertEquals(datum.value.toString(), result.value.toString());
|
||||||
|
|
||||||
Assert.assertNotNull(result);
|
|
||||||
Assert.assertEquals("value1", result.value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user