Skip to content

Commit

Permalink
fixes networknt#807 add portal-registry model for portal registry and…
Browse files Browse the repository at this point in the history
… discovery (networknt#808)
  • Loading branch information
stevehu authored Nov 15, 2020
1 parent 408cccd commit 485f6a8
Show file tree
Hide file tree
Showing 29 changed files with 2,269 additions and 0 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
<module>registry</module>
<module>balance</module>
<module>consul</module>
<module>portal-registry</module>
<module>zookeeper</module>
<module>cors</module>
<module>cluster</module>
Expand Down
74 changes: 74 additions & 0 deletions portal-registry/pom.xml
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>
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 portal-registry/src/integration/resources/config/service.yml
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 portal-registry/src/integration/resources/logback-test.xml
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>
Loading

0 comments on commit 485f6a8

Please sign in to comment.