<commit_before>/*
 * Telefónica Digital - Product Development and Innovation
 *
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
 *
 * Copyright (c) Telefónica Investigación y Desarrollo S.A.U.
 * All rights reserved.
 */

package es.tid.cosmos.platform.ial.libvirt

import scala.collection.concurrent
import scala.concurrent.duration._
import scala.concurrent.{Future, Await}
import scala.concurrent.ExecutionContext.Implicits.global

import org.scalatest.{BeforeAndAfter, FlatSpec}
import org.scalatest.matchers.MustMatchers

import es.tid.cosmos.platform.common.scalatest.matchers.{FutureMatchers, ForAllMatcher}
import es.tid.cosmos.platform.ial.{Id, ResourceExhaustedException, MachineState, MachineProfile}

class LibVirtInfrastructureProviderTest extends FlatSpec with MustMatchers with FutureMatchers with BeforeAndAfter {

  val timeout: FiniteDuration = 1 second
  var infraProvider: LibVirtInfrastructureProvider = null
  var action: TestBootstrapAction = null

  before {
    infraProvider = new LibVirtInfrastructureProvider(
      new FakeLibVirtDao, new FakeLibVirtServerFactory, "DUMMY-SSH-KEY")
    action = new TestBootstrapAction
  }

  after {}

  "Libvirt Infra Provider" must "create machines when available" in {
    val machines_> = infraProvider.createMachines(MachineProfile.G1Compute, 3, action)
    machines_> must runUnder (timeout)
    machines_> must eventually(have length 3)
    machines_> must eventually(matchAll.withProfile(MachineProfile.G1Compute))
    action.bootstrappedMachines must have size (3)
  }

  it must "not create machines when unavailable" in {
    mustNotCreateMachines(
      infraProvider.createMachines(MachineProfile.G1Compute, 30, action))
  }

  it must "not create machines when unavailable for requested profile" in {
    mustNotCreateMachines(
      infraProvider.createMachines(MachineProfile.HdfsMaster, 2, action))<commit_msg>Bump up timeout value to avoid issues in CI server<commit_after>/*
 * Telefónica Digital - Product Development and Innovation
 *
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
 *
 * Copyright (c) Telefónica Investigación y Desarrollo S.A.U.
 * All rights reserved.
 */

package es.tid.cosmos.platform.ial.libvirt

import scala.collection.concurrent
import scala.concurrent.duration._
import scala.concurrent.{Future, Await}
import scala.concurrent.ExecutionContext.Implicits.global

import org.scalatest.{BeforeAndAfter, FlatSpec}
import org.scalatest.matchers.MustMatchers

import es.tid.cosmos.platform.common.scalatest.matchers.{FutureMatchers, ForAllMatcher}
import es.tid.cosmos.platform.ial.{Id, ResourceExhaustedException, MachineState, MachineProfile}

class LibVirtInfrastructureProviderTest extends FlatSpec with MustMatchers with FutureMatchers with BeforeAndAfter {

  val timeout: FiniteDuration = 5 seconds
  var infraProvider: LibVirtInfrastructureProvider = null
  var action: TestBootstrapAction = null

  before {
    infraProvider = new LibVirtInfrastructureProvider(
      new FakeLibVirtDao, new FakeLibVirtServerFactory, "DUMMY-SSH-KEY")
    action = new TestBootstrapAction
  }

  after {}

  "Libvirt Infra Provider" must "create machines when available" in {
    val machines_> = infraProvider.createMachines(MachineProfile.G1Compute, 3, action)
    machines_> must runUnder (timeout)
    machines_> must eventually(have length 3)
    machines_> must eventually(matchAll.withProfile(MachineProfile.G1Compute))
    action.bootstrappedMachines must have size (3)
  }

  it must "not create machines when unavailable" in {
    mustNotCreateMachines(
      infraProvider.createMachines(MachineProfile.G1Compute, 30, action))
  }

  it must "not create machines when unavailable for requested profile" in {
    mustNotCreateMachines(
      infraProvider.createMachines(MachineProfile.HdfsMaster, 2, action))
{'fraction_non_alphanumeric': 0.07136015325670499, 'fraction_numerical': 0.004789272030651341, 'mean_word_length': 5.036127167630058, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1699712', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1164, 'n_words': 344}