Fix circle dependency error in Cluster

This commit is contained in:
KomachiSion 2020-05-29 14:18:08 +08:00
parent 810827c91c
commit 866f134262
2 changed files with 20 additions and 1 deletions

View File

@ -119,6 +119,7 @@ public class Cluster extends com.alibaba.nacos.api.naming.pojo.Cluster implement
} }
} }
@JsonIgnore
public HealthCheckTask getHealthCheckTask() { public HealthCheckTask getHealthCheckTask() {
return checkTask; return checkTask;
} }

View File

@ -17,9 +17,16 @@ package com.alibaba.nacos.naming.core;
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Http; import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Http;
import com.alibaba.nacos.common.utils.JacksonUtils; import com.alibaba.nacos.common.utils.JacksonUtils;
import com.alibaba.nacos.core.utils.ApplicationUtils;
import com.alibaba.nacos.naming.misc.SwitchDomain;
import com.alibaba.nacos.naming.misc.SwitchDomain.TcpHealthParams;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.context.ConfigurableApplicationContext;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -29,23 +36,34 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
/** /**
* @author nkorange * @author nkorange
*/ */
@RunWith(MockitoJUnitRunner.class)
public class ClusterTest { public class ClusterTest {
private Cluster cluster; private Cluster cluster;
@Mock
private ConfigurableApplicationContext context;
@Mock
private SwitchDomain switchDomain;
@Before @Before
public void before() { public void before() {
ApplicationUtils.injectContext(context);
when(context.getBean(SwitchDomain.class)).thenReturn(switchDomain);
when(switchDomain.getTcpHealthParams()).thenReturn(new TcpHealthParams());
Service service = new Service(); Service service = new Service();
service.setName("nacos.service.1"); service.setName("nacos.service.1");
cluster = new Cluster("nacos-cluster-1", service); cluster = new Cluster("nacos-cluster-1", service);
cluster.setDefCkport(80); cluster.setDefCkport(80);
cluster.setDefIPPort(8080); cluster.setDefIPPort(8080);
cluster.init();
} }