let assert = require('assert');
import Cassandra from '../cassandra';
import Utils from "../utils";
const defaultOptions = require("../../options.json");
import Settings from "../settings";


describe('cassandra', function () {
    it("reconnect test", function(done){
        this.timeout(1000);
        let first = true;

        Settings.Instance.setCassandra("test", {hosts: ["localhost"], port: 2201, autoConnect: true});
        let cassandra = new Cassandra("test");

        assert.equal(cassandra.getStatus(), "", "default status value");

        let controlConnection = cassandra.getControlConnection();

        assert.notEqual(controlConnection, null);

        controlConnection.on("newConnection", function(err: any, connection: any, host: any){
            if(first){
                assert.equal(cassandra.getStatus(), "Error", "error status");
                first = false;
                if(controlConnection)
                controlConnection.emit("newConnection", null);
            }else{
                assert.equal(cassandra.getStatus(), "Reconnected", "reconnected status");
                done();
            }
        });
    });
});