change grpc param
This commit is contained in:
parent
919b4bc4be
commit
f7bb1e3e20
|
@ -143,10 +143,12 @@ public class Server {
|
||||||
Object obj = null;
|
Object obj = null;
|
||||||
for (Init in : list) {
|
for (Init in : list) {
|
||||||
Crawler crawler = crawlerMap.get(in.getName().name());
|
Crawler crawler = crawlerMap.get(in.getName().name());
|
||||||
try {
|
if (crawler != null) {
|
||||||
obj = crawler.init(in.getData().toByteArray());
|
try {
|
||||||
} catch (Exception e) {
|
obj = crawler.init(in.getData().toByteArray());
|
||||||
e.printStackTrace();
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package com.loafle.overflow;
|
package com.loafle.overflow;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
import com.loafle.overflow.crawler.Crawler;
|
import com.loafle.overflow.crawler.Crawler;
|
||||||
import com.loafle.overflow.crawler.config.Config;
|
import com.loafle.overflow.crawler.config.Config;
|
||||||
import com.loafle.overflow.rpc.*;
|
import com.loafle.overflow.rpc.*;
|
||||||
|
@ -11,6 +14,9 @@ import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -54,14 +60,16 @@ public class ServerTest {
|
||||||
return ManagedChannelBuilder.forAddress(ip,port).usePlaintext(true).build();
|
return ManagedChannelBuilder.forAddress(ip,port).usePlaintext(true).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Output init() {
|
public Output init() throws IOException {
|
||||||
ConfigGrpc.ConfigBlockingStub client = newConfigClient("localhost",50052);
|
ConfigGrpc.ConfigBlockingStub client = newConfigClient("localhost",50052);
|
||||||
|
|
||||||
ClassLoader classLoader = getClass().getClassLoader();
|
ClassLoader classLoader = getClass().getClassLoader();
|
||||||
|
Path path = Paths.get(classLoader.getResource("config/example.json").getFile());
|
||||||
|
byte[] data = Files.readAllBytes(path);
|
||||||
|
ByteString sss = ByteString.copyFrom(data);
|
||||||
|
|
||||||
// path is test resources/config/example.json
|
|
||||||
Init input = Init.newBuilder().
|
Init input = Init.newBuilder().
|
||||||
setPath(classLoader.getResource("config").getFile()).
|
setData(sss).
|
||||||
setName(Crawlers.REDIS).build();
|
setName(Crawlers.REDIS).build();
|
||||||
InputArray arr = InputArray.newBuilder().addIn(input).build();
|
InputArray arr = InputArray.newBuilder().addIn(input).build();
|
||||||
|
|
||||||
|
@ -89,13 +97,15 @@ public class ServerTest {
|
||||||
|
|
||||||
ConfigGrpc.ConfigBlockingStub client = newConfigClient("localhost",50052);
|
ConfigGrpc.ConfigBlockingStub client = newConfigClient("localhost",50052);
|
||||||
|
|
||||||
ClassLoader classLoader = getClass().getClassLoader();
|
|
||||||
|
|
||||||
// path is test resources/config/example.json
|
// path is test resources/config/example.json
|
||||||
Input input = Input.newBuilder().
|
ClassLoader classLoader = getClass().getClassLoader();
|
||||||
setId("example.json").
|
Path path = Paths.get(classLoader.getResource("config/example.json").getFile());
|
||||||
setName(Crawlers.REDIS).build();
|
byte[] data = Files.readAllBytes(path);
|
||||||
|
ByteString sss = ByteString.copyFrom(data);
|
||||||
|
|
||||||
|
InputAdd input = InputAdd.newBuilder().
|
||||||
|
setData(sss).
|
||||||
|
setName(Crawlers.REDIS).build();
|
||||||
|
|
||||||
Output out = client.add(input);
|
Output out = client.add(input);
|
||||||
|
|
||||||
|
@ -141,7 +151,7 @@ public class ServerTest {
|
||||||
|
|
||||||
DataGrpc.DataBlockingStub client = newDataClient("localhost",50052);
|
DataGrpc.DataBlockingStub client = newDataClient("localhost",50052);
|
||||||
Input input = Input.newBuilder().
|
Input input = Input.newBuilder().
|
||||||
setId("example.json").
|
setId("SOEJWEOJWOEJOSDJFOASDJFOSDFO2903870928734").
|
||||||
setName(Crawlers.REDIS).build();
|
setName(Crawlers.REDIS).build();
|
||||||
|
|
||||||
Output out = client.get(input);
|
Output out = client.get(input);
|
||||||
|
|
|
@ -35,7 +35,7 @@ public class TestClient {
|
||||||
|
|
||||||
/** Say hello to server. */
|
/** Say hello to server. */
|
||||||
public void add() {
|
public void add() {
|
||||||
Input request = Input.newBuilder().setId("test111").setName(Crawlers.SNMP).build();
|
InputAdd request = InputAdd.newBuilder().setData(null).setName(Crawlers.SNMP).build();
|
||||||
Output response;
|
Output response;
|
||||||
try {
|
try {
|
||||||
response = configStub.add(request);
|
response = configStub.add(request);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user