/*
 Licensed to Diennea S.r.l. under one
 or more contributor license agreements. See the NOTICE file
 distributed with this work for additional information
 regarding copyright ownership. Diennea S.r.l. 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 herddb.server;

import herddb.client.ClientConfiguration;
import herddb.client.ClientSideMetadataProviderException;
import herddb.client.HDBClient;
import herddb.client.HDBConnection;
import herddb.client.HDBException;
import herddb.client.ScanResultSet;
import herddb.model.TableSpace;
import java.util.Collections;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

/**
 * SimpleServer boot test
 *
 * @author enrico.olivelli
 */
public class SimpleServerTest {

    @Rule
    public TemporaryFolder folder = new TemporaryFolder();

    @Test
    public void test() throws Exception {
        try {
            Thread runner = new Thread(() -> {
                ServerMain.main("src/test/resources/conf/test.server.properties");
            });
            runner.start();
            while (ServerMain.getRunningInstance() == null                     
                    || !ServerMain.getRunningInstance().isStarted()) {
                Thread.sleep(1000);
                System.out.println("waiting for boot");
            }

            ServerMain.getRunningInstance().getServer().waitForStandaloneBoot();
            
            try (HDBClient client = new HDBClient(new ClientConfiguration(folder.newFolder().toPath()))) {
                client.setClientSideMetadataProvider(
                        new StaticClientSideMetadataProvider(ServerMain.getRunningInstance().getServer()
                        ));
                try (HDBConnection con = client.openConnection()) {
                    try (ScanResultSet scan = con.executeScan(TableSpace.DEFAULT, "SELECT * FROM SYSTABLES", Collections.emptyList(), 0, 10, 10);) {
                        scan.consume();
                    }
                }
            }
            ServerMain.getRunningInstance().close();
        } finally {
            ServerMain.getRunningInstance().close();
        }
    }
}

@@ -821,66 +821,8 @@
 on;%0A
-import herddb.client.ClientSideMetadataProviderException;%0A
 impo
@@ -889,43 +889,8 @@
 on;%0A
-import herddb.client.HDBException;%0A
 impo
@@ -953,16 +953,98 @@
 eSpace;%0A
+import java.io.File;%0Aimport java.io.FileOutputStream;%0Aimport java.io.InputStream;%0A
 import j
@@ -1065,16 +1065,45 @@
 ctions;%0A
+import java.util.Properties;%0A
 import o
@@ -1430,123 +1430,631 @@
     
-Thread runner = new Thread(() -%3E %7B%0A                ServerMain.main(%22src/test/resources/conf/test.server.properties%22
+File tmpConfFile = folder.newFile(%22test.server.properties%22);%0A%0A            try (InputStream in = SimpleServerTest.class.getResourceAsStream(%22/conf/test.server.properties%22)) %7B%0A                Properties props = new Properties();%0A                props.load(in);%0A                props.put(ServerConfiguration.PROPERTY_BASEDIR, folder.newFolder().getAbsolutePath());%0A                try (FileOutputStream oo = new FileOutputStream(tmpConfFile)) %7B%0A                    props.store(oo, %22%22);%0A                %7D%0A            %7D%0A            Thread runner = new Thread(() -%3E %7B%0A                ServerMain.main(tmpConfFile.getAbsolutePath()
 );%0A 
@@ -2154,37 +2154,16 @@
  == null
-                     
 %0A       
@@ -2414,28 +2414,16 @@
 Boot();%0A
-            
 %0A       

fix tmp test dirs