OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CalciteViewsConcurrencyTest.java
Go to the documentation of this file.
1 /*
2  * Copyright 2015 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.mapd.tests;
17 
18 import static com.mapd.tests.HeavyDBAsserts.shouldThrowException;
19 
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22 
23 import java.util.ArrayList;
24 import java.util.List;
25 
27  final static Logger logger = LoggerFactory.getLogger(CalciteViewsConcurrencyTest.class);
28 
29  public static void main(String[] args) throws Exception {
31  test.testViewsResolutionConcurrency();
32  }
33 
34  public void testViewsResolutionConcurrency() throws Exception {
35  logger.info("testViewsResolutionConcurrency()");
36 
37  HeavyDBTestClient su = HeavyDBTestClient.getClient(
38  "localhost", 6274, "heavyai", "admin", "HyperInteractive");
39 
40  su.runSql("CREATE DATABASE db1;");
41  su.runSql("CREATE DATABASE db2;");
42 
43  HeavyDBTestClient db1 = HeavyDBTestClient.getClient(
44  "localhost", 6274, "db1", "admin", "HyperInteractive");
45  db1.runSql("create table table1 (id integer, description varchar(30));");
46  db1.runSql("create table table2 (id integer, description varchar(30));");
47  db1.runSql("insert into table1 values (1, 'hello');");
48  db1.runSql("insert into table2 values (1, 'db1');");
49  db1.runSql(
50  "create view v_goodview as select t1.id, t1.description, t2.description as tbl2Desc from db1.table1 t1, db1.table2 t2;");
51 
52  HeavyDBTestClient db2 = HeavyDBTestClient.getClient(
53  "localhost", 6274, "db2", "admin", "HyperInteractive");
54  db2.runSql("create table table1 (id integer, description varchar(30));");
55  db2.runSql("create table table2 (id integer, description varchar(30));");
56  db2.runSql("insert into table1 values (1, 'hello');");
57  db2.runSql("insert into table2 values (1, 'db2');");
58  db2.runSql(
59  "create view v_goodview as select t1.id, t1.description, t2.description as tbl2Desc from db2.table1 t1, db2.table2 t2;");
60 
61  int num_threads = 10;
62  Exception exceptions[] = new Exception[num_threads];
63  List<Thread> threads = new ArrayList<>();
64  for (int i = 0; i < num_threads; i++) {
65  final int threadId = i;
66  HeavyDBTestClient con1 = HeavyDBTestClient.getClient(
67  "localhost", 6274, "db1", "admin", "HyperInteractive");
68  HeavyDBTestClient con2 = HeavyDBTestClient.getClient(
69  "localhost", 6274, "db2", "admin", "HyperInteractive");
70  Thread t = new Thread(new Runnable() {
71  @Override
72  public void run() {
73  try {
74  for (int i = 0; i < 25; i++) {
75  con1.runSql("SELECT * FROM v_goodview;");
76  con2.runSql("SELECT * FROM v_goodview;");
77  }
78  } catch (Exception e) {
79  e.printStackTrace();
80  exceptions[threadId] = e;
81  }
82  }
83  });
84 
85  t.start();
86  threads.add(t);
87  }
88 
89  for (Thread t : threads) {
90  t.join();
91  }
92 
93  su.runSql("DROP DATABASE db1;");
94  su.runSql("DROP DATABASE db2;");
95 
96  for (Exception e : exceptions) {
97  if (null != e) {
98  throw e;
99  }
100  }
101  }
102 }
static bool run