MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NdbJTieSmokeTest.java
1 /*
2  Copyright 2010 Sun Microsystems, Inc.
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 /*
19  * NdbJTieSmokeTest.java
20  */
21 
22 package test;
23 
24 import com.mysql.ndbjtie.ndbapi.Ndb_cluster_connection;
25 import com.mysql.ndbjtie.ndbapi.Ndb;
26 import com.mysql.ndbjtie.ndbapi.NdbError;
27 
34 public class NdbJTieSmokeTest extends JTieTestBase {
35 
36  private String mgmdConnect = "localhost";
37  private String catalog = "crunddb";
38  private String schema = "def";
39 
40  private Ndb_cluster_connection mgmd;
41  private Ndb ndb;
42 
43  protected void init() {
44  // load native library
45  loadSystemLibrary("ndbclient");
46 
47  // Get system variable for other connect string
48  mgmdConnect = System.getProperty("jtie.unit.ndb.connectstring", mgmdConnect);
49 
50  // instantiate NDB cluster singleton
51  out.println();
52  out.println("creating cluster conn...");
53  mgmd = Ndb_cluster_connection.create(mgmdConnect);
54  assert mgmd != null;
55  out.println("... [ok, mgmd=" + mgmd + "]");
56 
57  // connect to cluster management node (ndb_mgmd)
58  out.println();
59  out.println("connecting to mgmd ...");
60  final int retries = 0; // retries (< 0 = indefinitely)
61  final int delay = 0; // seconds to wait after retry
62  final int verbose = 1; // print report of progess
63  // 0 = success, 1 = recoverable error, -1 = non-recoverable error
64  //if (Ndb_cluster_connection.connect(mgmd, retries, delay, verbose) != 0) {
65  if (mgmd.connect(retries, delay, verbose) != 0) {
66  final String msg = ("mgmd@" + mgmdConnect
67  + " was not ready within "
68  + (retries * delay) + "s.");
69  out.println(msg);
70  throw new RuntimeException(msg);
71  }
72  out.println("... [ok: " + mgmdConnect + "]");
73  }
74 
75  protected void close() {
76  out.println();
77  out.println("closing mgmd conn ...");
78  if (mgmd != null)
79  Ndb_cluster_connection.delete(mgmd);
80  out.println("... [ok, mgmd=" + mgmd + "]");
81  mgmd = null;
82 
83 /*
84  cout << "closing NDBAPI ... " << flush;
85  // ndb_close must be called last
86  ndb_end(0);
87  cout << " [ok]" << endl;
88 */
89  }
90 
91  protected void initConnection(String catalog, String schema) {
92  // optionally, connect and wait for reaching the data nodes (ndbds)
93  out.println();
94  out.println("waiting until ready...");
95  final int initial_wait = 10; // seconds to wait until first node detected
96  final int final_wait = 0; // seconds to wait after first node detected
97  // returns: 0 all nodes live, > 0 at least one node live, < 0 error
98  if (mgmd.wait_until_ready(initial_wait, final_wait) < 0) {
99  final String msg = ("data nodes were not ready within "
100  + (initial_wait + final_wait) + "s.");
101  out.println(msg);
102  throw new RuntimeException(msg);
103  }
104  out.println("... [ok]");
105 
106  // connect to database
107  out.println();
108  out.println("connecting to database...");
109  ndb = Ndb.create(mgmd, catalog, schema);
110  final int max_no_tx = 10; // maximum number of parallel tx (<=1024)
111  // note each scan or index scan operation uses one extra transaction
112  if (ndb.init(max_no_tx) != 0) {
113  String msg = "Error caught: " + ndb.getNdbError().message();
114  throw new RuntimeException(msg);
115  }
116  out.println("... [ok]");
117  }
118 
119  protected void closeConnection() {
120  out.println();
121  out.println("closing database conn ...");
122  Ndb.delete(ndb);
123  ndb = null;
124  out.println("... [ok]");
125  }
126 
127  public void test() {
128  out.println("--> NdbJTieSmokeTest.test()");
129 
130  init();
131  initConnection(catalog, schema);
132  closeConnection();
133  close();
134 
135  out.println();
136  out.println("<-- NdbJTieSmokeTest.test()");
137  };
138 
139  static public void main(String[] args) throws Exception {
140  out.println("--> NdbJTieSmokeTest.main()");
141 
142  out.println();
144  test.test();
145 
146  out.println();
147  out.println("<-- NdbJTieSmokeTest.main()");
148  }
149 }