<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.api.mocks.servicemanager

import org.scalatest.FlatSpec
import org.scalatest.matchers.MustMatchers

import es.tid.cosmos.servicemanager._

class MockedServiceManagerIT extends FlatSpec with MustMatchers {
  val transitionDelay = 100

  trait Instance {
    val instance = new MockedServiceManager(transitionDelay)
  }

  "A mocked service manager" must "be pre-populated with two clusters" in new Instance {
    instance.clusterIds must have size 2
  }

  it must "create a new cluster in provisioning state and then transition to running state" in new Instance {
    val id = instance.createCluster("small cluster", 10, serviceDescriptions = Seq(), users = Seq())
    instance.describeCluster(id).get must have ('state (Provisioning))
    Thread.sleep(5 * transitionDelay)
    instance.describeCluster(id).get must have ('state (Running))
  }

  it must "start terminating a cluster and then transition to terminated state" in new Instance {
    val id: ClusterId = MockedServiceManager.DefaultClusterId
    instance.terminateCluster(id)
    instance.describeCluster(id).get must have ('state (Terminating))
    Thread.sleep(5 * transitionDelay)
    instance.describeCluster(id).get must have ('state (Terminated))
  }
}<commit_msg>Fix race condition in ServiceManagerIT<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.api.mocks.servicemanager

import org.scalatest.FlatSpec
import org.scalatest.matchers.MustMatchers

import es.tid.cosmos.servicemanager._

class MockedServiceManagerIT extends FlatSpec with MustMatchers {
  val transitionDelay = 100

  trait Instance {
    val instance = new MockedServiceManager(transitionDelay)
  }

  "A mocked service manager" must "be pre-populated with two clusters" in new Instance {
    instance.clusterIds must have size 2
  }

  it must "create a new cluster in provisioning state and then transition to running state" in
    new Instance {
      val id = instance.createCluster(
        name = "small cluster",
        clusterSize = 10,
        serviceDescriptions = Seq.empty,
        users = Seq.empty
      )
      instance.describeCluster(id).get must (have('state (Provisioning)) or have('state (Running)))
      Thread.sleep(5 * transitionDelay)
      instance.describeCluster(id).get must have ('state (Running))
    }

  it must "start terminating a cluster and then transition to terminated state" in new Instance {
    val id: ClusterId = MockedServiceManager.DefaultClusterId
    instance.terminateCluster(id)
    instance.describeCluster(id).get must have ('state (Terminating))
    Thread.sleep(5 * transitionDelay)
    instance.describeCluster(id).get must have ('state (Terminated))
  }
}
{'fraction_non_alphanumeric': 0.0780388743835219, 'fraction_numerical': 0.004641717435451117, 'mean_word_length': 4.0780559646539025, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1223893', 'n_tokens_mistral': 977, 'n_tokens_neox': 937, 'n_words': 333}