]> review.fuel-infra Code Review - packages/trusty/mysql-wsrep-5.6.git/blob
f4a5299402d4e5cd06febeabf61f50867b6179d8
[packages/trusty/mysql-wsrep-5.6.git] /
1 /* -*- mode: java; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2  *  vim:expandtab:shiftwidth=4:tabstop=4:smarttab:
3  *
4  *  Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; version 2 of the License.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19
20 package com.mysql.cluster.benchmark.tws;
21
22 import java.io.PrintWriter;
23
24
25 abstract class TwsLoad {
26
27     // console
28     static protected final PrintWriter out = TwsDriver.out;
29     static protected final PrintWriter err = TwsDriver.err;
30
31     // resources
32     protected final TwsDriver driver;
33     protected String descr;
34
35     protected MetaData metaData;
36
37     protected static String fixedStr = "xxxxxxxxxx"
38             + "xxxxxxxxxx"
39             + "xxxxxxxxxx"
40             + "xxxxxxxxxx"
41             + "xxxxxxxxxx"
42             + "xxxxxxxxxx"
43             + "xxxxxxxxxx"
44             + "xxxxxxxxxx"
45             + "xxxxxxxxxx"
46             + "xxxxxxxxxx"
47             + "xxxxxxxxxx"
48             + "xxxxxxxxxx"
49             + "xxxxxxxxxx"
50             + "xxxxxxxxxx"
51             + "xxxxxxxxxx"
52             + "xxxxxxxxxx"
53             + "xxxxxxxxxx"
54             + "xxxxxxxxxx"
55             + "xxxxxxxxxx"
56             + "xxxxxxxxxx"
57             + "xxxxxxxxxx"
58             + "xxxxxxxxxx"
59             + "xxxxxxxxxx";
60
61     public TwsLoad(TwsDriver driver, MetaData md) {
62         this.driver = driver;
63         this.metaData = md;
64     }
65
66     // ----------------------------------------------------------------------
67     // intializers/finalizers
68     // ----------------------------------------------------------------------
69
70     abstract protected void initProperties();
71     abstract protected void printProperties();
72
73     public String getDescriptor() {
74         return descr;
75     }
76
77     public void init() throws Exception {
78         initProperties();
79         printProperties();
80     }
81
82     public void close() throws Exception {
83     }
84
85     public MetaData getMetaData() {
86         return metaData;
87     }
88
89     // ----------------------------------------------------------------------
90     // benchmark operations
91     // ----------------------------------------------------------------------
92
93     abstract public void runOperations() throws Exception;
94
95     // reports an error if a condition is not met
96     static protected final void verify(boolean cond) {
97         //assert (cond);
98         if (!cond)
99             throw new RuntimeException("data verification failed.");
100     }
101
102     static protected final void verify(int exp, int act) {
103         if (exp != act)
104             throw new RuntimeException("data verification failed:"
105                                        + " expected = " + exp
106                                        + ", actual = " + act);
107     }
108
109     static protected final void verify(String exp, String act) {
110         if ((exp == null && act != null)
111             || (exp != null && !exp.equals(act)))
112             throw new RuntimeException("data verification failed:"
113                                        + " expected = '" + exp + "'"
114                                        + ", actual = '" + act + "'");
115     }
116
117     // ----------------------------------------------------------------------
118     // datastore operations
119     // ----------------------------------------------------------------------
120
121     abstract public void initConnection() throws Exception;
122     abstract public void closeConnection() throws Exception;
123     //abstract public void clearPersistenceContext() throws Exception;
124     //abstract public void clearData() throws Exception;
125 }