File: ReplicationRun_Distributed.java

package info (click to toggle)
derby 10.14.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 78,896 kB
  • sloc: java: 691,930; sql: 42,686; xml: 20,511; sh: 3,373; sed: 96; makefile: 60
file content (339 lines) | stat: -rw-r--r-- 14,548 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
/*
 
Derby - Class org.apache.derbyTesting.functionTests.tests.replicationTests.ReplicationRun_Distributed
 
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at
 
   http://www.apache.org/licenses/LICENSE-2.0
 
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
 
 */
package org.apache.derbyTesting.functionTests.tests.replicationTests;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import junit.framework.Test;
import org.apache.derbyTesting.junit.BaseTestSuite;
import org.apache.derbyTesting.junit.SecurityManagerSetup;



/**
 * Run a replication test in a distributed
 * environment, where master and slave hosts, and
 * master and slave ports are specified in a property file.
 * Which test to run is also specified in the property file.
 * 
 */

public class ReplicationRun_Distributed extends ReplicationRun
{
    
    /**
     * Creates a new instance of ReplicationRun_Distributed
     * @param testcaseName Identifying the test.
     */
    public ReplicationRun_Distributed(String testcaseName)
    {
        super(testcaseName);
    }
    
    public static Test suite()
    {
        BaseTestSuite suite =
            new BaseTestSuite("ReplicationRun_Distributed Suite");
        
        suite.addTestSuite( ReplicationRun_Distributed.class );
        
        return SecurityManagerSetup.noSecurityManager(suite);
    }
    
    //////////////////////////////////////////////////////////////
    ////
    //// The replication test framework (testReplication()):
    //// a) "clean" replication run starting master and slave servers,
    ////     preparing master and slave databases,
    ////     starting and stopping replication and doing
    ////     failover for a "normal"/"failure free" replication
    ////     test run.
    ////
    //////////////////////////////////////////////////////////////
    
    public void testReplication()
    throws Exception
    {
        cleanAllTestHosts();
        
        initEnvironment();
        
        initMaster(masterServerHost,
                replicatedDb);
        
        startServer(masterJvmVersion, derbyMasterVersion,
                masterServerHost,
                ALL_INTERFACES, // masterServerHost, // "0.0.0.0", // All. or use masterServerHost for interfacesToListenOn,
                masterServerPort,
                masterDbSubPath); // Distinguishing master/slave
        
        startServer(slaveJvmVersion, derbySlaveVersion,
                slaveServerHost,
                ALL_INTERFACES, // slaveServerHost, // "0.0.0.0", // All. or use slaveServerHost for interfacesToListenOn,
                slaveServerPort,
                slaveDbSubPath); // Distinguishing master/slave
        
        startServerMonitor(slaveServerHost);
        
        bootMasterDatabase(jvmVersion,
                masterDatabasePath +FS+ masterDbSubPath,
                replicatedDb,
                masterServerHost, // Where the startreplication command must be given
                masterServerPort, // master server interface accepting client requests
                null // bootLoad, // The "test" to start when booting db.
                );
        
        initSlave(slaveServerHost,
                jvmVersion,
                replicatedDb); // Trunk and Prototype V2: copy master db to db_slave.
        
        startSlave(jvmVersion, replicatedDb,
                slaveServerHost, // slaveClientInterface // where the slave db runs
                slaveServerPort,
                slaveServerHost, // for slaveReplInterface
                slaveReplPort,
                testClientHost);
        
        // Allow the slave to reach the required state before attempting to start master:
        util.sleep(sleepTime, "Before startMaster");  // startMaster_ij should retry connection? 
        startMaster(jvmVersion, replicatedDb,
                masterServerHost, // Where the startMaster command must be given
                masterServerPort, // master server interface accepting client requests
                masterServerHost, // An interface on the master: masterClientInterface (==masterServerHost),
                slaveServerPort, // Not used since slave don't allow clients.
                slaveServerHost, // for slaveReplInterface
                slaveReplPort);
        
        
        // Used to run positive tests.
        // Handle negative testing in State.testPostStartedMasterAndSlave().
        // Observe that it will not be meaningful to do runTest if State.XXXX()
        // has led to incorrect replication state wrt. replicationTest.
        runTest(replicationTest, // Returns immediatly if replicationTest is null.
                jvmVersion,
                testClientHost,
                masterServerHost, masterServerPort,
                replicatedDb);
        
        failOver(jvmVersion,
                masterDatabasePath, masterDbSubPath, replicatedDb,
                masterServerHost,  // Where the master db is run.
                masterServerPort,
                testClientHost);
        
        connectPing(slaveDatabasePath+FS+slaveDbSubPath+FS+replicatedDb,
                slaveServerHost,slaveServerPort,
                testClientHost);
        
        verifySlave();
        
        // We should verify the master as well, at least to see that we still can connect.
        verifyMaster();
        
        stopServer(jvmVersion, derbyVersion,
                slaveServerHost, slaveServerPort);
        
        stopServer(jvmVersion, derbyVersion,
                masterServerHost, masterServerPort);
        // As of 2008-02-06 master does not accept shutdown after replication, so:
        // do a 'kill pid' after ending the test run
        
    }
    
    /**
     * When running in a distributed context,
     * the environment is defined via the REPLICATIONTEST_PROPFILE.
     */
    void initEnvironment()
    throws IOException
    {
        
        util.DEBUG("*** Properties -----------------------------------------");
        userDir = System.getProperty("user.dir");
        util.DEBUG("user.dir:          " + userDir);
        
        userHome = System.getProperty("user.home");
        util.DEBUG("user.home:          " + userHome);
        util.writeToFile("exit;", userHome+FS+"ij_dummy_script.sql");
        
        util.DEBUG("derby.system.home: " + System.getProperty("derby.system.home"));
        
        String realPropertyFile = REPLICATIONTEST_PROPFILE; // Is just the plain file name in ${user.dir}
        util.DEBUG("realPropertyFile: " + realPropertyFile);
        
        InputStream isCp =  new FileInputStream(userDir + FS + realPropertyFile);
        Properties cp = new Properties();
        // testRunProperties = cp; // Make available for e.g. new Load(loadId)
        cp.load(isCp);
        // testRunProperties = cp; // Make available for e.g. new Load(loadId)
        // Now we can get the derby jar path, jvm path etc.
        
        util.printDebug = cp.getProperty("test.printDebug","false").equalsIgnoreCase("true");
        util.DEBUG("printDebug: " + util.printDebug);
        
        showSysinfo = cp.getProperty("test.showSysinfo","false").equalsIgnoreCase("true");
        util.DEBUG("showSysinfo: " + showSysinfo);
        
        testUser = cp.getProperty("test.testUser","UNKNOWN");
        util.DEBUG("testUser: " + testUser);
        
        masterServerHost = cp.getProperty("test.masterServerHost",masterServerHost);
        util.DEBUG("masterServerHost: " + masterServerHost);
        cp.setProperty("test.serverHost", masterServerHost); // Set for initially running tests against master.
        
        masterServerPort = Integer.parseInt(cp.getProperty("test.masterServerPort",""+masterServerPort));
        util.DEBUG("masterServerPort: " + masterServerPort);
        cp.setProperty("test.serverPort", ""+masterServerPort); // Set for initially running tests against master.
        
        slaveServerHost = cp.getProperty("test.slaveServerHost",slaveServerHost);
        util.DEBUG("slaveServerHost: " + slaveServerHost);
        
        slaveServerPort = Integer.parseInt(cp.getProperty("test.slaveServerPort",""+slaveServerPort));
        util.DEBUG("slaveServerPort: " + slaveServerPort);
        
        slaveReplPort = Integer.parseInt(cp.getProperty("test.slaveReplPort",""+slaveReplPort));
        util.DEBUG("slaveReplPort: " + slaveReplPort);
        
        testClientHost = cp.getProperty("test.testClientHost",testClientHost);
        util.DEBUG("testClientHost: " + testClientHost);
        
        masterDatabasePath = cp.getProperty("test.master.databasepath");
        util.DEBUG("masterDatabasePath: " + masterDatabasePath);
        
        slaveDatabasePath = cp.getProperty("test.slave.databasepath");
        util.DEBUG("slaveDatabasePath: " + slaveDatabasePath);
        
        replicatedDb = cp.getProperty("test.databaseName","test");
        util.DEBUG("replicatedDb: " + replicatedDb);
        
        bootLoad = cp.getProperty("test.bootLoad");
        util.DEBUG("bootLoad: " + bootLoad);
        
        freezeDB = cp.getProperty("test.freezeDB");
        util.DEBUG("freezeDB: " + freezeDB);
        
        unFreezeDB = cp.getProperty("test.unFreezeDB");
        util.DEBUG("unFreezeDB: " + unFreezeDB);
        
        simpleLoad = System.getProperty("derby.tests.replSimpleLoad", "true")
                                                     .equalsIgnoreCase("true");
        util.DEBUG("simpleLoad: " + simpleLoad);
        simpleLoadTuples = Integer.parseInt(cp.getProperty("test.simpleloadtuples","10000"));
        util.DEBUG("simpleLoadTuples: " + simpleLoadTuples);
        
        replicationTest = cp.getProperty("test.replicationTest");
        util.DEBUG("replicationTest: " + replicationTest);
        replicationVerify = cp.getProperty("test.replicationVerify");
        util.DEBUG("replicationVerify: " + replicationVerify);
        junitTest = cp.getProperty("test.junitTest", "true")
                                                     .equalsIgnoreCase("true");
        util.DEBUG("junitTest: " + junitTest);
        
        THREADS = Integer.parseInt(cp.getProperty("test.stressMultiThreads","0"));
        util.DEBUG("THREADS: " + THREADS);
        MINUTES = Integer.parseInt(cp.getProperty("test.stressMultiMinutes","0"));
        util.DEBUG("MINUTES: " + MINUTES);
                
        sqlLoadInit = cp.getProperty("test.sqlLoadInit");
        util.DEBUG("sqlLoadInit: " + sqlLoadInit);

        
        specialTestingJar = cp.getProperty("test.derbyTestingJar", null);
        util.DEBUG("specialTestingJar: " + specialTestingJar);
        
        jvmVersion = cp.getProperty("jvm.version");
        util.DEBUG("jvmVersion: " + jvmVersion);
        
        masterJvmVersion = cp.getProperty("jvm.masterversion");
        if ( masterJvmVersion == null )
        {masterJvmVersion = jvmVersion;}
        util.DEBUG("masterJvmVersion: " + masterJvmVersion);
        
        slaveJvmVersion = cp.getProperty("jvm.slaveversion");
        if ( slaveJvmVersion == null )
        {slaveJvmVersion = jvmVersion;}
        util.DEBUG("slaveJvmVersion: " + slaveJvmVersion);
        
        derbyVersion = cp.getProperty("derby.version");
        util.DEBUG("derbyVersion: " + derbyVersion);
        
        derbyMasterVersion = cp.getProperty("derby.masterversion");
        if ( derbyMasterVersion == null )
        {derbyMasterVersion = derbyVersion;}
        util.DEBUG("derbyMasterVersion: " + derbyMasterVersion);
        
        derbySlaveVersion = cp.getProperty("derby.slaveversion");
        if ( derbySlaveVersion == null )
        {derbySlaveVersion = derbyVersion;}
        util.DEBUG("derbySlaveVersion: " + derbySlaveVersion);
        
        String derbyTestingJar = derbyVersion + FS+"derbyTesting.jar";
        if ( specialTestingJar != null )  derbyTestingJar = specialTestingJar;
        util.DEBUG("derbyTestingJar: " + derbyTestingJar);
        
        junit_jar = cp.getProperty("junit_jar");
        util.DEBUG("junit_jar: " + junit_jar);
        
        test_jars = derbyTestingJar
                + ":" + junit_jar
                ;
        util.DEBUG("test_jars: " + test_jars);
        
        sleepTime = Integer.parseInt(cp.getProperty("test.sleepTime","15000"));
        util.DEBUG("sleepTime: " + sleepTime);
        
        runUnReplicated = cp.getProperty("test.runUnReplicated","false").equalsIgnoreCase("true");
        util.DEBUG("runUnReplicated: " + runUnReplicated);
        
        localEnv = cp.getProperty("test.localEnvironment","false").equalsIgnoreCase("true");
        util.DEBUG("localEnv: " + localEnv);
        
        derbyProperties = 
                 "derby.infolog.append=true"+LF
                +"derby.drda.logConnections=true"+LF
                +"derby.drda.traceAll=true"+LF;

        
        util.DEBUG("--------------------------------------------------------");
        
        masterPreRepl = new Load("masterPreRepl", cp);
        masterPostRepl = new Load("masterPostRepl", cp);
        slavePreSlave = new Load("slavePreSlave", cp);
        masterPostSlave = new Load("masterPostSlave", cp);
        slavePostSlave = new Load("slavePostSlave", cp);
        
        util.DEBUG("--------------------------------------------------------");
        // for SimplePerfTest
        tuplesToInsertPerf = Integer.parseInt(cp.getProperty("test.inserts","10000"));
        util.DEBUG("tuplesToInsertPerf: " + tuplesToInsertPerf);
        commitFreq = Integer.parseInt(cp.getProperty("test.commitFreq","0")); // "0" is autocommit
        util.DEBUG("commitFreq: " + commitFreq);
        
        util.DEBUG("--------------------------------------------------------");
        
        state.initEnvironment(cp);
       
        util.DEBUG("--------------------------------------------------------");
       
    }
}