-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from mercyblitz/dev-1.x
Dev 1.x
- Loading branch information
Showing
6 changed files
with
111 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,24 +16,19 @@ | |
*/ | ||
package io.microsphere.spring.cloud.client.event; | ||
|
||
/** | ||
* TODO Comment | ||
* | ||
* @author <a href="mailto:[email protected]">Mercy</a> | ||
* @since TODO | ||
*/ | ||
|
||
import org.springframework.cloud.client.ServiceInstance; | ||
import org.springframework.context.ApplicationEvent; | ||
import org.springframework.context.event.ApplicationEventMulticaster; | ||
import org.springframework.context.event.SimpleApplicationEventMulticaster; | ||
import org.springframework.util.Assert; | ||
|
||
import java.util.List; | ||
|
||
import static java.util.Collections.unmodifiableList; | ||
import static org.springframework.util.Assert.notEmpty; | ||
|
||
/** | ||
* An event raised after the {@link ServiceInstance instances} of one service has been | ||
* An event raised when the {@link ServiceInstance instances} of one service has been | ||
* changed. | ||
* | ||
* @author <a href="mailto:[email protected]">Mercy</a> | ||
|
@@ -58,6 +53,7 @@ public class ServiceInstancesChangedEvent extends ApplicationEvent { | |
public ServiceInstancesChangedEvent(String serviceName, | ||
List<ServiceInstance> serviceInstances) { | ||
super(serviceName); | ||
notEmpty(serviceInstances, () -> "The arguments 'serviceInstances' must not be empty!"); | ||
this.serviceInstances = unmodifiableList(serviceInstances); | ||
} | ||
|
||
|
68 changes: 68 additions & 0 deletions
68
.../test/java/io/microsphere/spring/cloud/client/event/ServiceInstancesChangedEventTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package io.microsphere.spring.cloud.client.event; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.cloud.client.DefaultServiceInstance; | ||
import org.springframework.cloud.client.ServiceInstance; | ||
|
||
import java.net.URI; | ||
import java.util.Arrays; | ||
import java.util.UUID; | ||
|
||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertSame; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
/** | ||
* {@link ServiceInstancesChangedEvent} Test | ||
* | ||
* @author <a href="mailto:[email protected]">Mercy<a/> | ||
* @see ServiceInstancesChangedEvent | ||
* @since 1.0.0 | ||
*/ | ||
public class ServiceInstancesChangedEventTest { | ||
|
||
private String serviceName = "testService"; | ||
|
||
private ServiceInstancesChangedEvent event; | ||
|
||
private ServiceInstance instance; | ||
|
||
@BeforeEach | ||
public void init() { | ||
this.instance = createInstance(serviceName); | ||
this.event = new ServiceInstancesChangedEvent(serviceName, Arrays.asList(instance)); | ||
} | ||
|
||
private ServiceInstance createInstance(String serviceName) { | ||
DefaultServiceInstance instance = new DefaultServiceInstance(); | ||
instance.setServiceId(serviceName); | ||
instance.setServiceId(UUID.randomUUID().toString()); | ||
instance.setHost("127.0.0.1"); | ||
instance.setPort(8080); | ||
instance.setUri(URI.create("http://127.0.0.1:8080/info")); | ||
return instance; | ||
} | ||
|
||
@Test | ||
public void testGetServiceName() { | ||
assertEquals(this.serviceName, this.event.getServiceName()); | ||
assertEquals(this.serviceName, this.event.getSource()); | ||
} | ||
|
||
@Test | ||
public void testGetServiceInstances() { | ||
assertEquals(Arrays.asList(this.instance), this.event.getServiceInstances()); | ||
assertEquals(this.instance, this.event.getServiceInstances().get(0)); | ||
assertSame(this.instance, this.event.getServiceInstances().get(0)); | ||
} | ||
|
||
@Test | ||
public void testProcessed() { | ||
assertFalse(this.event.isProcessed()); | ||
this.event.processed(); | ||
assertTrue(this.event.isProcessed()); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...ing/cloud/client/service/registry/autoconfigure/ServiceRegistryAutoConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.microsphere.spring.cloud.client.service.registry.autoconfigure; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
/** | ||
* {@link ServiceRegistryAutoConfiguration} Test | ||
* | ||
* @author <a href="mailto:[email protected]">Mercy<a/> | ||
* @see ServiceRegistryAutoConfiguration | ||
* @since 1.0.0 | ||
*/ | ||
public class ServiceRegistryAutoConfigurationTest { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters