Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing the package #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package in.ashwanthkumar.matsya
package com.indix.matsya

import java.io.File
import java.util.concurrent.TimeUnit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package in.ashwanthkumar.matsya
package com.indix.matsya

import java.lang.reflect.{ParameterizedType, Type}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package in.ashwanthkumar.matsya
package com.indix.matsya

import java.lang.{Double => JDouble}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package in.ashwanthkumar.matsya
package com.indix.matsya

import in.ashwanthkumar.slack.webhook.{Slack, SlackMessage}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package in.ashwanthkumar.matsya
package com.indix.matsya

import java.io.File

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package in.ashwanthkumar.matsya
package com.indix.matsya

object ClusterMode {
val Spot = 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package in.ashwanthkumar.matsya
package com.indix.matsya

case class Metric(machineType: String,
az: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package in.ashwanthkumar.matsya
package com.indix.matsya

import com.typesafe.scalalogging.slf4j.Logger
import org.slf4j.LoggerFactory
Expand Down
37 changes: 37 additions & 0 deletions src/test/scala/com/indix/matsya/ClusterConfigTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.indix.matsya

import com.typesafe.config.ConfigFactory
import org.scalatest.FlatSpec
import org.scalatest.Matchers.{be, convertToAnyShouldWrapper}


class ClusterConfigTest extends FlatSpec {

"ClusterConfig Object" should "create ClusterConfig from config " in {

val config = ConfigFactory.parseURL(this.getClass.getResource("/test-cluster-config.conf"))

val actualClusterConfig = ClusterConfig.from(config)

actualClusterConfig.name should be("Test Hadoop Cluster")
actualClusterConfig.spotASG should be("test-asg-spot")
actualClusterConfig.odASG should be("test-asg-od")
actualClusterConfig.machineType should be("c3.2xlarge")
actualClusterConfig.maxBidPrice should be(0.420)
actualClusterConfig.maxThreshold should be(0.8)
actualClusterConfig.maxNrOfTimes should be(5)
actualClusterConfig.odPrice should be(0.420)
actualClusterConfig.fallBackToOnDemand should be(true)
actualClusterConfig.odCoolOffPeriodInMillis should be(2700000)

val expectedSubnetsMap = Map("us-east-1c" -> "subnet-3",
"us-east-1d" -> "subnet-4",
"us-east-1a" -> "subnet-1",
"us-east-1e" -> "subnet-5",
"us-east-1b" -> "subnet-2")

actualClusterConfig.subnets should be(expectedSubnetsMap)

}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package in.ashwanthkumar.matsya
package com.indix.matsya

import org.scalatest.FlatSpec
import org.scalatest.Matchers.{be, convertToAnyShouldWrapper, have}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package in.ashwanthkumar.matsya
package com.indix.matsya

import org.scalatest.FlatSpec
import org.scalatest.Matchers.{be, convertToAnyShouldWrapper}
Expand Down
77 changes: 77 additions & 0 deletions src/test/scala/com/indix/matsya/MatsyaTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.indix.matsya

import com.amazonaws.services.autoscaling.AmazonAutoScalingClient
import com.amazonaws.services.ec2.AmazonEC2Client
import org.joda.time.{DateTime, DateTimeUtils}
import org.mockito.Mockito.{mock, when}
import org.scalatest.FlatSpec
import org.scalatest.Matchers.{be, convertToAnyShouldWrapper}


class MatsyaTest extends FlatSpec {

"hasCooledOff " should "return true when cool off time is greater than given in config" in {
val clusterConfig = mock(classOf[ClusterConfig])

val c2Client = mock(classOf[AmazonEC2Client])
val autoScalingClient = mock(classOf[AmazonAutoScalingClient])
val timeSeriesStore = mock(classOf[TimeSeriesStore])
val stateStore = mock(classOf[StateStore])
val notifier = mock(classOf[Notifier])

val matsyaConfig = MatsyaConfig(List(clusterConfig), "", None)

val Matsya = new Matsya(c2Client, autoScalingClient, matsyaConfig, timeSeriesStore, stateStore, notifier)

val state = mock(classOf[State])

val nowTimeInMilli = DateTime.now.getMillis

val lastModeChangedTimestamp = DateTime.now.minusHours(1).getMillis

DateTimeUtils.setCurrentMillisFixed(nowTimeInMilli)

when(state.lastModeChangedTimestamp).thenReturn(lastModeChangedTimestamp)

val millisecsFor30Secs = 30000

when(clusterConfig.odCoolOffPeriodInMillis).thenReturn(millisecsFor30Secs)

Matsya.hasCooledOff(clusterConfig, state) should be(true)


}

it should "return false when cool off time is lesser than given in config" in {
val clusterConfig = mock(classOf[ClusterConfig])

val c2Client = mock(classOf[AmazonEC2Client])
val autoScalingClient = mock(classOf[AmazonAutoScalingClient])
val timeSeriesStore = mock(classOf[TimeSeriesStore])
val stateStore = mock(classOf[StateStore])
val notifier = mock(classOf[Notifier])

val matsyaConfig = MatsyaConfig(List(clusterConfig), "", None)

val Matsya = new Matsya(c2Client, autoScalingClient, matsyaConfig, timeSeriesStore, stateStore, notifier)

val state = mock(classOf[State])

val nowTimeInMilli = DateTime.now.getMillis

val lastModeChangedTimestamp = DateTime.now.minusSeconds(1).getMillis

DateTimeUtils.setCurrentMillisFixed(nowTimeInMilli)

when(state.lastModeChangedTimestamp).thenReturn(lastModeChangedTimestamp)

val millisecsFor30Secs = 30000

when(clusterConfig.odCoolOffPeriodInMillis).thenReturn(millisecsFor30Secs)

Matsya.hasCooledOff(clusterConfig, state) should be(false)


}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package in.ashwanthkumar.matsya

import java.io.File

import com.indix.matsya.ClusterConfig
import com.typesafe.config.ConfigFactory
import org.scalatest.FlatSpec
import org.scalatest.Matchers.{be, convertToAnyShouldWrapper}
Expand Down
1 change: 1 addition & 0 deletions src/test/scala/in/ashwanthkumar/matsya/MatsyaTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package in.ashwanthkumar.matsya

import com.amazonaws.services.autoscaling.AmazonAutoScalingClient
import com.amazonaws.services.ec2.AmazonEC2Client
import com.indix.matsya._
import org.joda.time.{DateTime, DateTimeUtils}
import org.mockito.Mockito.{mock, when}
import org.scalatest.FlatSpec
Expand Down