/**************************************************************************************
 *
 *     Project:    kvmstoreserver-tools
 *     File name:  main.go
 *     Version:    1.0.0
 *     Date:       2018-01-15
 *
 *     Autor:      Bogdanovic Theodor
 *     Contact:    t.bogdanovic@hotmail.com
 *
 *     License:    GPLv3
 *
 **************************************************************************************/
/**************************************************************************************
 * Copyright 2018 Bogdanovic Theodor
 *
 * This file is part of kvmstoreserver-tools.
 *
 * kvmstoreserver-tools is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * kvmstoreserver-tools is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with kvmstoreserver-tools.  If not, see <http://www.gnu.org/licenses/>.
 **************************************************************************************/
/**************************************************************************************
 *  Further explanations:  This source code is under the license specified by the
 *                         Autor above. Core components or other packages are still
 *                         in source code form, under the license specified by the
 *                         respective author.
 **************************************************************************************/

package main

import (
	"checker"
	"client"
	"fmt"
	"runtime"
	"time"
	"utils"
)

func main() {

	const maxParaReqs int = 6000
	var endNbr int

	cmdArgs := utils.NewCmdController()
	synchronizer := client.ParaController{}
	start := time.Now()

	if cmdArgs.GetStart() != 0 {
		endNbr = cmdArgs.GetStart() + 6000
	} else {
		endNbr = maxParaReqs
	}

	for idx := cmdArgs.GetStart(); idx < endNbr; idx++ {

		synchronizer.Wg.Add(1)
		go client.NewWorker(idx, cmdArgs.GetTarget()).StartRequest(&synchronizer)
	}
	synchronizer.Wg.Wait()

	runtime.GC()

	fmt.Printf("\nToral duration of all (%v) parallel requests -> %v\n",
		maxParaReqs, time.Since(start))

	fmt.Printf("\nThe default key pattern is \"System_Name_<%v - %v>\"", cmdArgs.GetStart(), endNbr-1)
	fmt.Printf(`

		EXAMPLE:
			http://<IP or domain name>:3344/get/System_Name_0
			`)

	fmt.Printf("Start trying to get the last entry from kvmstoreserver:")

	fmt.Printf("\nRESULT -> %v",
		checker.GetRandomEntry(cmdArgs.GetTarget(), endNbr-1))

}
