11'use strict' ;
22const fs = require ( 'fs' ) ;
33const os = require ( 'os' ) ;
4- const net = require ( 'net' ) ;
54const { spawnSync, spawn} = require ( 'child_process' ) ;
65const codeSampleChecker = require ( './code-sample-checker' ) ;
76
8- const {
9- HAZELCAST_RC_VERSION ,
10- HAZELCAST_TEST_VERSION ,
11- HAZELCAST_ENTERPRISE_VERSION ,
12- HAZELCAST_VERSION ,
13- downloadRC
14- } = require ( './download-rc.js' ) ;
15-
167const DEV_CLUSTER_CONFIG = `
178 <hazelcast xmlns="http://www.hazelcast.com/schema/config"
189 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -23,8 +14,6 @@ const DEV_CLUSTER_CONFIG = `
2314 </hazelcast>
2415` ;
2516const ON_WINDOWS = os . platform ( ) === 'win32' ;
26- const HAZELCAST_ENTERPRISE_KEY = process . env . HAZELCAST_ENTERPRISE_KEY ? process . env . HAZELCAST_ENTERPRISE_KEY : '' ;
27- const PATH_SEPARATOR = ON_WINDOWS ? ';' : ':' ;
2817
2918let cluster ; // We create a cluster for checking code samples
3019
@@ -33,97 +22,12 @@ let testType;
3322let rcProcess ;
3423let testProcess ;
3524let runTests = true ;
36- let CLASSPATH = `hazelcast-remote-controller-${ HAZELCAST_RC_VERSION } .jar${ PATH_SEPARATOR } `
37- + `hazelcast-${ HAZELCAST_TEST_VERSION } -tests.jar${ PATH_SEPARATOR } `
38- + `hazelcast-sql-${ HAZELCAST_VERSION } .jar${ PATH_SEPARATOR } ` ;
39-
40- if ( HAZELCAST_ENTERPRISE_KEY ) {
41- CLASSPATH = `hazelcast-enterprise-${ HAZELCAST_ENTERPRISE_VERSION } .jar${ PATH_SEPARATOR } `
42- + `certs.jar${ PATH_SEPARATOR } `
43- + CLASSPATH ;
44- } else {
45- CLASSPATH = `hazelcast-${ HAZELCAST_VERSION } .jar${ PATH_SEPARATOR } ${ CLASSPATH } ` ;
46- }
47-
48- const isAddressReachable = ( host , port , timeoutMs ) => {
49- return new Promise ( ( resolve ) => {
50- const socket = new net . Socket ( ) ;
51- socket . setTimeout ( timeoutMs ) ;
52- const onError = ( ) => {
53- socket . destroy ( ) ;
54- resolve ( false ) ;
55- } ;
56- socket . once ( 'error' , onError ) ;
57- socket . once ( 'timeout' , onError ) ;
58- socket . connect ( port , host , ( ) => {
59- socket . end ( ) ;
60- resolve ( true ) ;
61- } ) ;
62- } ) ;
63- } ;
6425
6526// Import lazily to defer side affect of the import (connection attempt to 9701)
6627const getRC = ( ) => {
6728 return require ( '../test/integration/RC' ) ;
6829} ;
6930
70- const startRC = async ( ) => {
71- console . log ( 'Starting Hazelcast Remote Controller ...' ) ;
72- if ( ON_WINDOWS ) {
73- const outFD = fs . openSync ( 'rc_stdout.log' , 'w' ) ;
74- const errFD = fs . openSync ( 'rc_stderr.log' , 'w' ) ;
75- rcProcess = spawn ( 'java' , [
76- `-Dhazelcast.enterprise.license.key=${ HAZELCAST_ENTERPRISE_KEY } ` ,
77- '-cp' ,
78- CLASSPATH ,
79- 'com.hazelcast.remotecontroller.Main'
80- ] , {
81- stdio : [
82- 'ignore' ,
83- outFD ,
84- errFD
85- ]
86- } ) ;
87- rcProcess . on ( 'close' , ( ) => {
88- fs . closeSync ( outFD ) ;
89- fs . closeSync ( errFD ) ;
90- } ) ;
91- } else {
92- const outFD = fs . openSync ( 'rc_stdout.log' , 'w' ) ;
93- const errFD = fs . openSync ( 'rc_stderr.log' , 'w' ) ;
94- rcProcess = spawn ( 'java' , [
95- `-Dhazelcast.enterprise.license.key=${ HAZELCAST_ENTERPRISE_KEY } ` ,
96- '-cp' ,
97- CLASSPATH ,
98- 'com.hazelcast.remotecontroller.Main'
99- ] , {
100- stdio : [
101- 'ignore' ,
102- outFD ,
103- errFD
104- ]
105- } ) ;
106- rcProcess . on ( 'close' , ( ) => {
107- fs . closeSync ( outFD ) ;
108- fs . closeSync ( errFD ) ;
109- } ) ;
110- }
111-
112- console . log ( 'Please wait for Hazelcast Remote Controller to start ...' ) ;
113-
114- const retryCount = 100 ;
115-
116- for ( let i = 0 ; i < retryCount ; i ++ ) {
117- console . log ( 'Trying to connect to Hazelcast Remote Controller (127.0.0.1:9701)...' ) ;
118- const addressReachable = await isAddressReachable ( '127.0.0.1' , 9701 , 5000 ) ;
119- if ( addressReachable ) {
120- return ;
121- }
122- await new Promise ( r => setTimeout ( r , 1000 ) ) ;
123- }
124- throw `Could not reach to Hazelcast Remote Controller (127.0.0.1:9701) after trying ${ retryCount } times.` ;
125- } ;
126-
12731const shutdown = async ( ) => {
12832 if ( testProcess && testProcess . exitCode === null ) {
12933 stopTestProcess ( ) ;
@@ -229,19 +133,11 @@ if (testType === 'unit') {
229133 process . exit ( subprocess . status ) ;
230134}
231135
232- // For other tests, download rc files if needed.
233- try {
234- downloadRC ( ) ;
235- } catch ( err ) {
236- console . log ( 'An error occurred downloading remote controller:' ) ;
237- throw err ;
238- }
239-
240136process . on ( 'SIGINT' , shutdown ) ;
241137process . on ( 'SIGTERM' , shutdown ) ;
242138process . on ( 'SIGHUP' , shutdown ) ;
243139
244- startRC ( ) . then ( async ( ) => {
140+ ( async ( ) => {
245141 console . log ( 'Hazelcast Remote Controller is started!' ) ;
246142 if ( runTests ) {
247143 console . log ( `Running ${ testType } , Command: ${ testCommand } ` ) ;
@@ -265,7 +161,7 @@ startRC().then(async () => {
265161 process . exit ( exitCode ) ;
266162 }
267163 }
268- } ) . catch ( err => {
164+ } ) ( ) . catch ( err => {
269165 console . log ( 'Could not start Hazelcast Remote Controller due to an error:' ) ;
270166 throw err ;
271167} ) ;
0 commit comments