Created
May 3, 2018 09:01
-
-
Save yanns/b72644b5a24f82533de3a7c4e0db09bf to your computer and use it in GitHub Desktop.
test of elasticsearch data nodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.UUID | |
import scala.collection.JavaConverters._ | |
import scala.concurrent.duration._ | |
class DataSpec extends BaseSpec { | |
private def recoverFrom(action: ⇒ Unit): Unit = { | |
val index = s"index-${UUID.randomUUID().toString}" | |
eventually { | |
withHealthCheck { json ⇒ | |
(json \ "number_of_data_nodes").asOpt[Int].value should be (2) | |
(json \ "status").asOpt[String].value should be ("green") | |
} | |
} | |
esClient.createIndex(index) | |
esClient.indexDocs(index) | |
esClient.searchDocsSuccessful(index) | |
action | |
eventually(timeout(5 minutes)) { | |
withHealthCheck { json ⇒ | |
(json \ "number_of_data_nodes").asOpt[Int].value should be(2) | |
(json \ "status").asOpt[String].value should be("green") | |
} | |
dataPods().list().getItems.asScala.map(_.getMetadata.getName) should have size 2 | |
esClient.searchDocsSuccessful(index) | |
} | |
} | |
"Elastic search data nodes" should { | |
"be deployed on several pods" in { | |
dataPods().list().getItems.asScala.map(_.getMetadata.getName) should have size 2 | |
} | |
"be deployed on different physical nodes" in { | |
val allHostIPs = dataPods().list().getItems.asScala.map(_.getStatus.getHostIP).toVector | |
allHostIPs.toSet should contain theSameElementsAs allHostIPs | |
} | |
"recover shutdown of one node" in { | |
recoverFrom { | |
logger.debug("killing one data node") | |
kube.pods().delete(dataPods().list().getItems.get(0)) | |
} | |
} | |
"recover shutdown of all nodes" in { | |
recoverFrom { | |
logger.debug("killing all data nodes") | |
dataPods().withGracePeriod(0).delete() | |
} | |
} | |
"be monitored for health" in { | |
dataPods().list().getItems.asScala.map { pod ⇒ | |
pod.getSpec().getContainers().asScala.map { container ⇒ | |
container.getReadinessProbe() should not be (null) | |
} | |
} | |
} | |
} | |
private def dataPods() = | |
kube.pods().withLabel("app", "elasticsearch").withLabel("component", "data") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment