Skip to content

Commit

Permalink
Close Terracotta-OSS#191: Failover tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed Dec 20, 2016
1 parent d29ac19 commit b02635c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ public <T> T getService(long consumerID, ServiceConfiguration<T> configuration)
// get or creates a client-side monitoring service
if (ClientMonitoringService.class == serviceType) {
if (configuration instanceof ClientMonitoringServiceConfiguration) {
// this guard prevents an entity using a monitoring service if the platform did not previously sent us the right topology events
// this service cannot be used if the topology is not right
if (!topologyService.isCurrentServerActive()) {
throw new IllegalStateException("Server " + platformConfiguration.getServerName() + " is not active!");
}
Expand All @@ -200,6 +202,8 @@ public <T> T getService(long consumerID, ServiceConfiguration<T> configuration)
// get or creates a monitoring accessor service (for tms)
if (ManagementService.class == serviceType) {
if (configuration instanceof ManagementServiceConfiguration) {
// this guard prevents an entity using a monitoring service if the platform did not previously sent us the right topology events
// this service cannot be used if the topology is not right
if (!topologyService.isCurrentServerActive()) {
throw new IllegalStateException("Server " + platformConfiguration.getServerName() + " is not active!");
}
Expand All @@ -222,6 +226,8 @@ public <T> T getService(long consumerID, ServiceConfiguration<T> configuration)
// get or creates a monitoring service for an active entity
if (ActiveEntityMonitoringService.class == serviceType) {
if (configuration instanceof ActiveEntityMonitoringServiceConfiguration) {
// this guard prevents an entity using a monitoring service if the platform did not previously sent us the right topology events
// this service cannot be used if the topology is not right
if (!topologyService.isCurrentServerActive()) {
throw new IllegalStateException("Server " + platformConfiguration.getServerName() + " is not active!");
}
Expand All @@ -241,6 +247,8 @@ public <T> T getService(long consumerID, ServiceConfiguration<T> configuration)
// get or creates a monitoring service for a passive entity, bridging calls to IMonitoringProducer
if (PassiveEntityMonitoringService.class == serviceType) {
if (configuration instanceof PassiveEntityMonitoringServiceConfiguration) {
// this guard prevents an entity using a monitoring service if the platform did not previously sent us the right topology events
// this service cannot be used if the topology is not right
if (topologyService.isCurrentServerActive()) {
throw new IllegalStateException("Server " + platformConfiguration.getServerName() + " is not passive!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,70 @@
*/
package org.terracotta.management.integration.tests;

import org.junit.Ignore;
import org.junit.Before;
import org.junit.Test;
import org.terracotta.management.model.capabilities.descriptors.Settings;
import org.terracotta.management.model.cluster.Cluster;
import org.terracotta.management.model.cluster.Server;
import org.terracotta.management.model.cluster.ServerEntity;
import org.terracotta.management.model.message.Message;
import org.terracotta.management.model.notification.ContextualNotification;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;

/**
* @author Mathieu Carbou
*/
@Ignore("Impacted by https://github.com/Terracotta-OSS/terracotta-core/issues/405")
//TODO: VOLTRON ISSUE ? https://github.com/Terracotta-OSS/terracotta-core/issues/405
public class FailoverIT extends AbstractHATest {

@Test
public void failover_management() throws Exception {
Server oldActive;
Server oldPassive;

@Override
@Before
public void setUp() throws Exception {
super.setUp();

Cluster cluster = tmsAgentService.readTopology();
Server active = cluster.serverStream().filter(Server::isActive).findFirst().get();
Server passive = cluster.serverStream().filter(server -> !server.isActive()).findFirst().get();
assertThat(active.getState(), equalTo(Server.State.ACTIVE));
assertThat(passive.getState(), equalTo(Server.State.PASSIVE));
oldActive = cluster.serverStream().filter(Server::isActive).findFirst().get();
oldPassive = cluster.serverStream().filter(server -> !server.isActive()).findFirst().get();
assertThat(oldActive.getState(), equalTo(Server.State.ACTIVE));
assertThat(oldPassive.getState(), equalTo(Server.State.PASSIVE));

// clear buffer
tmsAgentService.readMessages();

// kill active - passive should take the active role
System.out.printf("==> terminateActive()");
voltron.getClusterControl().terminateActive();
System.out.printf("==> waitForActive()");
voltron.getClusterControl().waitForActive();
}

System.out.printf("==> readTopology()");
cluster = tmsAgentService.readTopology();
@Test
public void topology_recovery_after_failover() throws Exception {
Cluster cluster = tmsAgentService.readTopology();

// verify new server
Server newActive = cluster.serverStream().filter(Server::isActive).findFirst().get();
assertThat(newActive.getState(), equalTo(Server.State.ACTIVE));
assertThat(newActive.getServerName(), equalTo(passive.getServerName()));
assertThat(newActive.getServerName(), equalTo(oldPassive.getServerName()));

// removes all random values
String currentTopo = toJson(cluster.toMap()).toString();
String actual = removeRandomValues(currentTopo);

String expected = readJson("topology.json").toString();
assertEquals(expected, actual);
}

@Test
public void notifications_after_failover() throws Exception {
// read messages
List<Message> messages = tmsAgentService.readMessages();

Expand All @@ -74,7 +94,7 @@ public void failover_management() throws Exception {

assertThat(
notifs.stream().map(notif -> notif.getContext().get(Server.NAME_KEY)).collect(Collectors.toList()),
equalTo(Arrays.asList(newActive.getServerName(), newActive.getServerName())));
equalTo(Arrays.asList(oldPassive.getServerName(), oldPassive.getServerName())));

assertThat(
notifs.stream().map(notif -> notif.getAttributes().get("state")).collect(Collectors.toList()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,7 @@ public void can_read_topology() throws Exception {
Cluster cluster = tmsAgentService.readTopology();
String currentTopo = toJson(cluster.toMap()).toString();
String actual = removeRandomValues(currentTopo);


String expected = readJson("topology.json").toString();

System.out.println("This is the actual topology : " + actual);
System.out.println("This is the expected topology : " + expected);
// and compare
assertEquals(expected, actual);
}

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
<terracotta-apis.version>1.1.0</terracotta-apis.version>
<tcconfig.version>10.1.0</tcconfig.version>
<passthrough-testing.version>1.1.1-pre2</passthrough-testing.version>
<terracotta-core.version>5.1.1-pre2</terracotta-core.version>
<galvan.version>1.1.1-pre2</galvan.version>
<terracotta-core.version>5.2-SNAPSHOT</terracotta-core.version>
<galvan.version>1.2-SNAPSHOT</galvan.version>
<statistics.version>1.4.1</statistics.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
Expand Down

0 comments on commit b02635c

Please sign in to comment.