Skip to content

Commit

Permalink
Merge branch 'master' into example
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicole00 authored Dec 21, 2021
2 parents c5fdf04 + ede2cb2 commit 1f467b8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.google.common.base.Preconditions;
import com.google.common.net.InetAddresses;
import com.vesoft.nebula.client.graph.data.HostAddress;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;

public class AbstractMetaClient {
Expand All @@ -22,16 +24,16 @@ public class AbstractMetaClient {
protected TTransport transport;

public AbstractMetaClient(List<HostAddress> addresses, int timeout,
int connectionRetry, int executionRetry) {
int connectionRetry, int executionRetry) throws UnknownHostException {
Preconditions.checkArgument(timeout > 0);
Preconditions.checkArgument(connectionRetry > 0);
Preconditions.checkArgument(executionRetry > 0);
Preconditions.checkArgument(connectionRetry >= 0);
Preconditions.checkArgument(executionRetry >= 0);
for (HostAddress address : addresses) {
String host = address.getHost();
String host = InetAddress.getByName(address.getHost()).getHostAddress();
int port = address.getPort();
// check if the address is a valid ip address or uri address and port is valid
if ((!InetAddresses.isInetAddress(host) || !InetAddresses.isUriInetAddress(host))
|| (port <= 0 || port >= 65535)) {
|| (port <= 0 || port >= 65535)) {
throw new IllegalArgumentException(String.format("%s:%d is not a valid address",
host, port));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import com.vesoft.nebula.meta.VerifyClientVersionResp;
import com.vesoft.nebula.util.SslUtil;
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -75,30 +76,32 @@ public class MetaClient extends AbstractMetaClient {
private MetaService.Client client;
private final List<HostAddress> addresses;

public MetaClient(String host, int port) {
public MetaClient(String host, int port) throws UnknownHostException {
this(new HostAddress(host, port));
}

public MetaClient(HostAddress address) {
public MetaClient(HostAddress address) throws UnknownHostException {
this(Arrays.asList(address), DEFAULT_CONNECTION_RETRY_SIZE, DEFAULT_EXECUTION_RETRY_SIZE);
}

public MetaClient(List<HostAddress> addresses) {
public MetaClient(List<HostAddress> addresses) throws UnknownHostException {
this(addresses, DEFAULT_CONNECTION_RETRY_SIZE, DEFAULT_EXECUTION_RETRY_SIZE);
}

public MetaClient(List<HostAddress> addresses, int connectionRetry, int executionRetry) {
public MetaClient(List<HostAddress> addresses, int connectionRetry, int executionRetry)
throws UnknownHostException {
this(addresses, DEFAULT_TIMEOUT_MS, connectionRetry, executionRetry);
}

public MetaClient(List<HostAddress> addresses, int timeout, int connectionRetry,
int executionRetry) {
int executionRetry) throws UnknownHostException {
super(addresses, timeout, connectionRetry, executionRetry);
this.addresses = addresses;
}

public MetaClient(List<HostAddress> addresses, int timeout, int connectionRetry,
int executionRetry, boolean enableSSL, SSLParam sslParam) {
int executionRetry, boolean enableSSL, SSLParam sslParam)
throws UnknownHostException {
super(addresses, timeout, connectionRetry, executionRetry);
this.addresses = addresses;
this.enableSSL = enableSSL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.vesoft.nebula.meta.IdName;
import com.vesoft.nebula.meta.SpaceItem;
import com.vesoft.nebula.meta.TagItem;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -55,7 +56,7 @@ private class SpaceInfo {
* init the meta info cache
*/
public MetaManager(List<HostAddress> address)
throws TException, ClientServerIncompatibleException {
throws TException, ClientServerIncompatibleException, UnknownHostException {
metaClient = new MetaClient(address);
metaClient.connect();
fillMetaInfo();
Expand All @@ -66,7 +67,7 @@ public MetaManager(List<HostAddress> address)
*/
public MetaManager(List<HostAddress> address, int timeout, int connectionRetry,
int executionRetry, boolean enableSSL, SSLParam sslParam)
throws TException, ClientServerIncompatibleException {
throws TException, ClientServerIncompatibleException, UnknownHostException {
metaClient = new MetaClient(address, timeout, connectionRetry, executionRetry, enableSSL,
sslParam);
metaClient.connect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.vesoft.nebula.meta.IdName;
import com.vesoft.nebula.meta.TagItem;
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
Expand All @@ -43,21 +44,22 @@ public void tearDown() throws Exception {
}

private void connect() {
metaClient = new MetaClient(address, port);
try {
metaClient = new MetaClient(address, port);
metaClient.connect();
} catch (TException | ClientServerIncompatibleException e) {
} catch (TException | UnknownHostException | ClientServerIncompatibleException e) {
e.printStackTrace();
assert (false);
}
}

public void testFailConnect() {
int port = 1111;
MetaClient client = new MetaClient(address, port);

try {
MetaClient client = new MetaClient(address, port);
client.connect();
} catch (TException | ClientServerIncompatibleException e) {
} catch (TException | UnknownHostException | ClientServerIncompatibleException e) {
assert (true);
}
}
Expand Down Expand Up @@ -107,7 +109,11 @@ public void testGetPartsAlloc() {

public void testListHosts() {
if (metaClient == null) {
metaClient = new MetaClient(address, port);
try {
metaClient = new MetaClient(address, port);
} catch (UnknownHostException e) {
assert (false);
}
}
assert (metaClient.listHosts().size() == 3);
}
Expand All @@ -126,7 +132,11 @@ public void testListOnlineHosts() {
assert (false);
}
if (metaClient == null) {
metaClient = new MetaClient(address, port);
try {
metaClient = new MetaClient(address, port);
} catch (UnknownHostException e) {
assert (false);
}
}
assert (metaClient.listHosts().size() == 2);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.vesoft.nebula.meta.SpaceItem;
import com.vesoft.nebula.meta.TagItem;
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -107,8 +108,12 @@ public void testGetSpaceParts() {
public void testMultiVersionSchema() throws ClientServerIncompatibleException {
MockNebulaGraph.createMultiVersionTagAndEdge();
metaManager.close();
metaManager = new MetaManager(
Collections.singletonList(new HostAddress("127.0.0.1", 9559)));
try {
metaManager = new MetaManager(
Collections.singletonList(new HostAddress("127.0.0.1", 9559)));
} catch (UnknownHostException e) {
assert (false);
}
TagItem tagItem = metaManager.getTag("testMeta", "player");
assert (tagItem.getVersion() == 1);
assert (tagItem.schema.getColumns().size() == 1);
Expand Down

0 comments on commit 1f467b8

Please sign in to comment.