Search in sources :

Example 11 with Conformity

use of com.netflix.simianarmy.conformity.Conformity in project SimianArmy by Netflix.

the class TestRDSConformityClusterTracker method testInsertNewCluster.

@SuppressWarnings("unchecked")
@Test
public void testInsertNewCluster() {
    // mock the select query that is issued to see if the record already exists
    ArrayList<Cluster> clusters = new ArrayList<>();
    TestRDSConformityClusterTracker tracker = new TestRDSConformityClusterTracker();
    when(tracker.getJdbcTemplate().query(Matchers.anyString(), Matchers.any(Object[].class), Matchers.any(RowMapper.class))).thenReturn(clusters);
    Cluster cluster1 = new Cluster("clustername1", "us-west-1");
    cluster1.setUpdateTime(new Date());
    ArrayList<String> list = new ArrayList<>();
    list.add("one");
    list.add("two");
    cluster1.updateConformity(new Conformity("rule1", list));
    list.add("three");
    cluster1.updateConformity(new Conformity("rule2", list));
    ArgumentCaptor<Object> objCap = ArgumentCaptor.forClass(Object.class);
    ArgumentCaptor<String> sqlCap = ArgumentCaptor.forClass(String.class);
    when(tracker.getJdbcTemplate().update(sqlCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture())).thenReturn(1);
    tracker.addOrUpdate(cluster1);
    List<Object> args = objCap.getAllValues();
    Assert.assertEquals(args.size(), 9);
    Assert.assertEquals(args.get(0).toString(), "clustername1");
    Assert.assertEquals(args.get(1).toString(), "us-west-1");
    Assert.assertEquals(args.get(7).toString(), "{\"rule1\":\"one,two\",\"rule2\":\"one,two,three\"}");
    Assert.assertEquals(args.get(8).toString(), "rule1,rule2");
}
Also used : ArrayList(java.util.ArrayList) Cluster(com.netflix.simianarmy.conformity.Cluster) Conformity(com.netflix.simianarmy.conformity.Conformity) Date(java.util.Date) RowMapper(org.springframework.jdbc.core.RowMapper) Test(org.testng.annotations.Test)

Example 12 with Conformity

use of com.netflix.simianarmy.conformity.Conformity in project SimianArmy by Netflix.

the class TestInstanceInVPC method testAsgInstances.

@Test
public void testAsgInstances() throws Exception {
    AutoScalingGroup autoScalingGroup = new AutoScalingGroup("Conforming", VPC_INSTANCE_ID);
    Cluster conformingCluster = new Cluster("Conforming", REGION, autoScalingGroup);
    Conformity result = instanceInVPC.check(conformingCluster);
    Assert.assertNotNull(result);
    Assert.assertEquals(result.getRuleId(), instanceInVPC.getName());
    Assert.assertEquals(result.getFailedComponents().size(), 0);
    autoScalingGroup = new AutoScalingGroup("NonConforming", INSTANCE_ID);
    Cluster nonConformingCluster = new Cluster("NonConforming", REGION, autoScalingGroup);
    result = instanceInVPC.check(nonConformingCluster);
    Assert.assertNotNull(result);
    Assert.assertEquals(result.getRuleId(), instanceInVPC.getName());
    Assert.assertEquals(result.getFailedComponents().size(), 1);
    Assert.assertEquals(result.getFailedComponents().iterator().next(), INSTANCE_ID);
}
Also used : AutoScalingGroup(com.netflix.simianarmy.conformity.AutoScalingGroup) Cluster(com.netflix.simianarmy.conformity.Cluster) Conformity(com.netflix.simianarmy.conformity.Conformity) Test(org.testng.annotations.Test)

Aggregations

Conformity (com.netflix.simianarmy.conformity.Conformity)12 AutoScalingGroup (com.netflix.simianarmy.conformity.AutoScalingGroup)9 Cluster (com.netflix.simianarmy.conformity.Cluster)4 Test (org.testng.annotations.Test)3 Map (java.util.Map)2 MonkeyRestClient (com.netflix.simianarmy.client.MonkeyRestClient)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 RowMapper (org.springframework.jdbc.core.RowMapper)1