forked from networknt/light-4j
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes networknt#807 add portal-registry model for portal registry and…
… discovery (networknt#808)
- Loading branch information
Showing
29 changed files
with
2,269 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<!-- | ||
~ Copyright (c) 2016 Network New Technologies Inc. | ||
~ | ||
~ Licensed 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. | ||
--> | ||
|
||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>com.networknt</groupId> | ||
<artifactId>light-4j</artifactId> | ||
<version>2.0.21-SNAPSHOT</version> | ||
<relativePath>..</relativePath> | ||
</parent> | ||
|
||
<artifactId>portal-registry</artifactId> | ||
<packaging>jar</packaging> | ||
<description>A registry and discovery client that integrates with light-portal</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.networknt</groupId> | ||
<artifactId>config</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.networknt</groupId> | ||
<artifactId>utility</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.networknt</groupId> | ||
<artifactId>http-string</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.networknt</groupId> | ||
<artifactId>registry</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.networknt</groupId> | ||
<artifactId>client</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
76 changes: 76 additions & 0 deletions
76
portal-registry/src/integration/java/com/networknt/portal/registry/PortalRegistryTestIT.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,76 @@ | ||
/* | ||
* Copyright (c) 2016 Network New Technologies Inc. | ||
* | ||
* Licensed 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 com.networknt.portal.registry; | ||
|
||
import com.networknt.registry.Registry; | ||
import com.networknt.registry.URL; | ||
import com.networknt.registry.URLImpl; | ||
import com.networknt.service.SingletonServiceFactory; | ||
import org.junit.*; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class PortalRegistryTestIT { | ||
private PortalRegistry registry; | ||
private URL serviceUrl; | ||
private long sleepTime; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
registry = (PortalRegistry)SingletonServiceFactory.getBean(Registry.class); | ||
|
||
|
||
serviceUrl = getMockUrl("http", "192.168.1.119",8083, "MockService"); | ||
|
||
sleepTime = PortalRegistryConstants.SWITCHER_CHECK_CIRCLE + 500; | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
registry = null; | ||
} | ||
|
||
@Test | ||
@Ignore | ||
public void doRegisterAndAvailable() throws Exception { | ||
// register | ||
registry.doRegister(serviceUrl); | ||
|
||
// unregister | ||
registry.doUnregister(serviceUrl); | ||
} | ||
|
||
@Test | ||
@Ignore | ||
public void discoverService() throws Exception { | ||
registry.doRegister(serviceUrl); | ||
List<URL> urls = registry.discoverService(serviceUrl); | ||
Assert.assertEquals(urls.size(), 0); | ||
Thread.sleep(sleepTime); | ||
urls = registry.discoverService(serviceUrl); | ||
//Assert.assertTrue(urls.contains(serviceUrl)); | ||
} | ||
|
||
public static URL getMockUrl(String protocol, String address, int port, String serviceName) { | ||
Map<String, String> params = new HashMap<>(); | ||
params.put("environment", "test1"); | ||
URL url = new URLImpl(protocol, address, port, serviceName, params); | ||
return url; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
portal-registry/src/integration/resources/config/service.yml
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,17 @@ | ||
singletons: | ||
- com.networknt.registry.URL: | ||
- com.networknt.registry.URLImpl: | ||
protocol: light | ||
host: localhost | ||
port: 8080 | ||
path: consul | ||
parameters: | ||
registryRetryPeriod: '30000' | ||
- com.networknt.portal.registry.client.PortalRegistryClient: | ||
- com.networknt.portal.registry.client.PortalRegistryClientImpl | ||
- com.networknt.registry.Registry: | ||
- com.networknt.portal.registry.PortalRegistry | ||
- com.networknt.balance.LoadBalance: | ||
- com.networknt.balance.RoundRobinLoadBalance | ||
- com.networknt.cluster.Cluster: | ||
- com.networknt.cluster.LightCluster |
49 changes: 49 additions & 0 deletions
49
portal-registry/src/integration/resources/logback-test.xml
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,49 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright (c) 2016 Network New Technologies Inc. | ||
~ | ||
~ Licensed 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. | ||
--> | ||
|
||
<configuration> | ||
<turboFilter class="ch.qos.logback.classic.turbo.MarkerFilter"> | ||
<Marker>PROFILER</Marker> | ||
<!--<OnMatch>DENY</OnMatch>--> | ||
<OnMatch>NEUTRAL</OnMatch> | ||
</turboFilter> | ||
|
||
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender"> | ||
<!-- encoders are assigned the type | ||
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default --> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5marker %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<appender name="log" class="ch.qos.logback.core.FileAppender"> | ||
<File>target/test.log</File> | ||
<Append>false</Append> | ||
<layout class="ch.qos.logback.classic.PatternLayout"> | ||
<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %class{36}:%L %M - %msg%n</Pattern> | ||
</layout> | ||
</appender> | ||
|
||
<root level="trace"> | ||
<appender-ref ref="stdout" /> | ||
</root> | ||
|
||
<logger name="com.networknt" level="trace"> | ||
<appender-ref ref="log"/> | ||
</logger> | ||
|
||
</configuration> |
Oops, something went wrong.