Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get the latest schema & add test #316

Merged
merged 6 commits into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public static MetaManager getMetaManager(List<HostAddress> address) throws TExce
* close meta client
*/
public void close() {
metaManager = null;
metaClient.close();
}

Expand All @@ -99,16 +100,23 @@ private void fillMetaInfo() {
spaceInfo.spaceItem = spaceItem;
List<TagItem> tags = metaClient.getTags(spaceName);
for (TagItem tag : tags) {
spaceInfo.tagItems.put(new String(tag.tag_name), tag);
spaceInfo.tagIdNames.put(tag.tag_id, new String(tag.tag_name));
String tagName = new String(tag.tag_name);
if (!spaceInfo.tagItems.containsKey(tagName)
|| spaceInfo.tagItems.get(tagName).getVersion() < tag.getVersion()) {
spaceInfo.tagItems.put(tagName, tag);
spaceInfo.tagIdNames.put(tag.tag_id, tagName);
}
}
List<EdgeItem> edges = metaClient.getEdges(spaceName);
for (EdgeItem edge : edges) {
spaceInfo.edgeItems.put(new String(edge.edge_name), edge);
spaceInfo.edgeTypeNames.put(edge.edge_type, new String(edge.edge_name));
String edgeName = new String(edge.edge_name);
if (!spaceInfo.edgeItems.containsKey(edgeName)
|| spaceInfo.edgeItems.get(edgeName).getVersion() < edge.getVersion()) {
spaceInfo.edgeItems.put(edgeName, edge);
spaceInfo.edgeTypeNames.put(edge.edge_type, edgeName);
}
}
Map<Integer, List<HostAddr>> partsAlloc = metaClient.getPartsAlloc(spaceName);
spaceInfo.partsAlloc = partsAlloc;
spaceInfo.partsAlloc = metaClient.getPartsAlloc(spaceName);
tempSpacesInfo.put(spaceName, spaceInfo);
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public void setUp() throws Exception {
Assert.assertTrue(pool.init(Arrays.asList(new HostAddress("127.0.0.1", 9671)),
nebulaPoolConfig));
session = pool.getSession("root", "nebula", true);
ResultSet resp = session.execute("CREATE SPACE IF NOT EXISTS test_data; "
ResultSet resp = session.execute("CREATE SPACE IF NOT EXISTS test_data"
+ "(vid_type=fixed_string(8)); "
+ "USE test_data;"
+ "CREATE TAG IF NOT EXISTS person(name string, age int8, grade int16, "
+ "friends int32, book_num int64, birthday datetime, "
Expand Down Expand Up @@ -201,8 +202,8 @@ public void testSet() {
setVal.stream().sorted().collect(Collectors.toList()));

Assert.assertEquals(result.toString(),
"ColumnName: [{\"name\",\"name\",\"age\",\"birthday\"}], "
+ "Rows: [[\"name\", \"birthday\", \"age\"]]");
"ColumnName: [{\"name\",\"name\",\"age\",\"birthday\"}], "
+ "Rows: [[\"name\", \"birthday\", \"age\"]]");
} catch (IOErrorException | UnsupportedEncodingException e) {
e.printStackTrace();
assert false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class TestSession {
private static void printProcessStatus(String cmd, Process p) {
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(p.getInputStream()));
new InputStreamReader(p.getInputStream()));

String line;
System.out.print(cmd + " output: ");
Expand Down Expand Up @@ -67,11 +67,11 @@ public void testMultiThreadUseTheSameSession() {
executorService.shutdown();
assert failedCount.get() > 0;
Assert.assertTrue(exceptionStr.get().contains(
"Multi threads use the same session, "
+ "the previous execution was not completed, current thread is:"));
"Multi threads use the same session, "
+ "the previous execution was not completed, current thread is:"));
} catch (Exception e) {
e.printStackTrace();
Assert.assertFalse(e.getMessage(),false);
Assert.assertFalse(e.getMessage(), false);
} finally {
pool.close();
}
Expand All @@ -85,21 +85,21 @@ public void testReconnectWithOneService() {
NebulaPoolConfig nebulaPoolConfig = new NebulaPoolConfig();
nebulaPoolConfig.setMaxConnSize(1);
List<HostAddress> addresses = Arrays.asList(
new HostAddress("127.0.0.1", 9669));
new HostAddress("127.0.0.1", 9669));
Assert.assertTrue(pool.init(addresses, nebulaPoolConfig));
Session session = pool.getSession("root", "nebula", true);
session.release();

Runtime runtime = Runtime.getRuntime();
runtime.exec("docker restart nebula-docker-compose_graphd0_1")
.waitFor(5, TimeUnit.SECONDS);
.waitFor(5, TimeUnit.SECONDS);
TimeUnit.SECONDS.sleep(5);
// the connections in pool are broken, test getSession can get right connection
session = pool.getSession("root", "nebula", true);

// the connections in pool are broken, test execute can get right connection
runtime.exec("docker restart nebula-docker-compose_graphd0_1")
.waitFor(5, TimeUnit.SECONDS);
.waitFor(5, TimeUnit.SECONDS);
TimeUnit.SECONDS.sleep(5);
session.execute("SHOW SPACES");
session.release();
Expand All @@ -126,9 +126,9 @@ public void testReconnectWithMultiServices() {
NebulaPoolConfig nebulaPoolConfig = new NebulaPoolConfig();
nebulaPoolConfig.setMaxConnSize(6);
List<HostAddress> addresses = Arrays.asList(
new HostAddress("127.0.0.1", 9669),
new HostAddress("127.0.0.1", 9670),
new HostAddress("127.0.0.1", 9671));
new HostAddress("127.0.0.1", 9669),
new HostAddress("127.0.0.1", 9670),
new HostAddress("127.0.0.1", 9671));
Assert.assertTrue(pool.init(addresses, nebulaPoolConfig));
Session session = pool.getSession("root", "nebula", true);
System.out.println("The address of session is " + session.getGraphHost());
Expand All @@ -137,7 +137,8 @@ public void testReconnectWithMultiServices() {
Assert.assertTrue(session.ping());

ResultSet resp = session.execute(
"CREATE SPACE IF NOT EXISTS test_session; USE test_session;");
"CREATE SPACE IF NOT EXISTS test_session(vid_type=fixed_string(8)); "
+ "USE test_session;");
Assert.assertTrue(resp.isSucceeded());
for (int i = 0; i < 10; i++) {
if (i == 3) {
Expand Down Expand Up @@ -174,13 +175,13 @@ public void testReconnectWithMultiServices() {

} catch (Exception e) {
e.printStackTrace();
Assert.assertFalse(e.getMessage(),false);
Assert.assertFalse(e.getMessage(), false);
} finally {
try {
runtime.exec("docker start nebula-docker-compose_graphd0_1")
.waitFor(5, TimeUnit.SECONDS);
.waitFor(5, TimeUnit.SECONDS);
runtime.exec("docker start nebula-docker-compose_graphd1_1")
.waitFor(5, TimeUnit.SECONDS);
.waitFor(5, TimeUnit.SECONDS);
TimeUnit.SECONDS.sleep(5);
} catch (Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* two spaces: test1, test2, both have 2 parts
* each space has one tag and one edge
*/
public class MockNebulaGraph {
public static void initGraph() {
private static final Logger LOGGER = LoggerFactory.getLogger(MockNebulaGraph.class);

public static void initGraph() {
NebulaPoolConfig nebulaPoolConfig = new NebulaPoolConfig();
nebulaPoolConfig.setMaxConnSize(100);
List<HostAddress> addresses = Arrays.asList(new HostAddress("127.0.0.1", 9669),
Expand All @@ -37,6 +40,7 @@ public static void initGraph() {

ResultSet resp = session.execute(createSpace());
if (!resp.isSucceeded()) {
LOGGER.error(resp.getErrorMessage());
System.exit(1);
}
} catch (UnknownHostException | NotValidConnectionException
Expand All @@ -48,10 +52,50 @@ public static void initGraph() {
}

public static String createSpace() {
String exec = "CREATE SPACE IF NOT EXISTS testMeta(partition_num=10);"
String exec = "CREATE SPACE IF NOT EXISTS testMeta(partition_num=10, "
+ "vid_type=fixed_string(8));"
+ "USE testMeta;"
+ "CREATE TAG IF NOT EXISTS person(name string, age int);"
+ "CREATE EDGE IF NOT EXISTS friend(likeness double);";
return exec;
}

public static void createMultiVersionTagAndEdge() {
NebulaPoolConfig nebulaPoolConfig = new NebulaPoolConfig();
nebulaPoolConfig.setMaxConnSize(100);
List<HostAddress> addresses = Arrays.asList(new HostAddress("127.0.0.1", 9669),
new HostAddress("127.0.0.1", 9670));
NebulaPool pool = new NebulaPool();
Session session = null;
try {
pool.init(addresses, nebulaPoolConfig);
session = pool.getSession("root", "nebula", true);

String exec = "CREATE SPACE IF NOT EXISTS testMeta(partition_num=10, "
+ "vid_type=fixed_string(10));"
+ "USE testMeta;"
+ "CREATE TAG IF NOT EXISTS player();"
+ "CREATE EDGE IF NOT EXISTS couples()";
ResultSet resp = session.execute(exec);
if (!resp.isSucceeded()) {
LOGGER.error(resp.getErrorMessage());
System.exit(1);
}
Thread.sleep(10000);
String updateSchema = "USE testMeta;"
+ "ALTER TAG player ADD(col1 string);"
+ "ALTER EDGE couples ADD(col1 string)";
ResultSet updateResp = session.execute(updateSchema);
if (!updateResp.isSucceeded()) {
if (!"Existed!".equals(updateResp.getErrorMessage())) {
LOGGER.error(resp.getErrorMessage());
System.exit(1);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
pool.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class TestMetaManager extends TestCase {
public void setUp() throws Exception {
MockNebulaGraph.initGraph();
metaManager = MetaManager.getMetaManager(
Collections.singletonList(new HostAddress("127.0.0.1", 9559)));
Collections.singletonList(new HostAddress("127.0.0.1", 9559)));
}

public void tearDown() {
Expand Down Expand Up @@ -82,7 +82,7 @@ public void testGetEdge() {
public void testGetSpaceParts() {
assert (metaManager.getSpaceParts("testMeta").size() == 10);
Assert.assertArrayEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).toArray(),
metaManager.getSpaceParts("testMeta").toArray());
metaManager.getSpaceParts("testMeta").toArray());

// test get leader
HostAddr hostAddr = metaManager.getLeader("testMeta", 1);
Expand All @@ -96,4 +96,18 @@ public void testGetSpaceParts() {
Assert.assertNotNull(hostAddr);
Assert.assertEquals(hostAddr.port, 4400);
}
}

public void testMultiVersionSchema() {
MockNebulaGraph.createMultiVersionTagAndEdge();
metaManager.close();
metaManager = MetaManager.getMetaManager(
Collections.singletonList(new HostAddress("127.0.0.1", 9559)));
TagItem tagItem = metaManager.getTag("testMeta", "player");
assert (tagItem.getVersion() == 1);
assert (tagItem.schema.getColumns().size() == 1);

EdgeItem edgeItem = metaManager.getEdge("testMeta", "couples");
assert (edgeItem.getVersion() == 1);
assert (edgeItem.schema.getColumns().size() == 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public static void initGraph() {
}

public static String createSpace() {
String exec = "CREATE SPACE IF NOT EXISTS testStorage(partition_num=10);"
String exec = "CREATE SPACE IF NOT EXISTS testStorage(partition_num=10,"
+ "vid_type=fixed_string(8));"
+ "USE testStorage;"
+ "CREATE TAG IF NOT EXISTS person(name string, age int);"
+ "CREATE EDGE IF NOT EXISTS friend(likeness double);";
Expand Down