forked from Terracotta-OSS/terracotta-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ Terracotta-OSS#191: Failover Galvan tests
- Loading branch information
1 parent
1726507
commit 9e9ac37
Showing
7 changed files
with
679 additions
and
215 deletions.
There are no files selected for viewing
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
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
70 changes: 70 additions & 0 deletions
70
...ation-tests/src/test/java/org/terracotta/management/integration/tests/PassiveLeaveIT.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright Terracotta, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.terracotta.management.integration.tests; | ||
|
||
import org.junit.Test; | ||
import org.terracotta.management.model.cluster.Server; | ||
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 static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.junit.Assert.assertThat; | ||
|
||
/** | ||
* @author Mathieu Carbou | ||
*/ | ||
public class PassiveLeaveIT extends AbstractHATest { | ||
|
||
@Test | ||
public void get_notifications_when_passive_leaves() throws Exception { | ||
Server active = tmsAgentService.readTopology().serverStream().filter(Server::isActive).findFirst().get(); | ||
Server passive = tmsAgentService.readTopology().serverStream().filter(server -> !server.isActive()).findFirst().get(); | ||
assertThat(active.getState(), equalTo(Server.State.ACTIVE)); | ||
assertThat(passive.getState(), equalTo(Server.State.PASSIVE)); | ||
|
||
// clear notification buffer | ||
tmsAgentService.readMessages(); | ||
|
||
// remove one passive | ||
voltron.getClusterControl().terminateOnePassive(); | ||
|
||
// wait for SERVER_LEFT message | ||
List<Message> messages; | ||
do { | ||
messages = tmsAgentService.readMessages(); | ||
} | ||
while (messages.isEmpty() && !Thread.currentThread().isInterrupted()); | ||
|
||
assertThat(messages.stream() | ||
.filter(message -> message.getType().equals("NOTIFICATION")) | ||
.flatMap(message -> message.unwrap(ContextualNotification.class).stream()) | ||
.map(ContextualNotification::getType) | ||
.collect(Collectors.toList()), | ||
equalTo(Arrays.asList("SERVER_LEFT"))); | ||
|
||
assertThat(messages.stream() | ||
.filter(message -> message.getType().equals("NOTIFICATION")) | ||
.flatMap(message -> message.unwrap(ContextualNotification.class).stream()) | ||
.map(contextualNotification -> contextualNotification.getContext().get(Server.NAME_KEY)) | ||
.collect(Collectors.toList()), | ||
equalTo(Arrays.asList(passive.getServerName()))); | ||
} | ||
|
||
} |
126 changes: 126 additions & 0 deletions
126
...ion-tests/src/test/java/org/terracotta/management/integration/tests/PassiveStartupIT.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Copyright Terracotta, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.terracotta.management.integration.tests; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.terracotta.management.model.cluster.Server; | ||
import org.terracotta.management.model.message.Message; | ||
import org.terracotta.management.model.notification.ContextualNotification; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.core.IsCollectionContaining.hasItem; | ||
import static org.junit.Assert.assertThat; | ||
|
||
/** | ||
* @author Mathieu Carbou | ||
*/ | ||
public class PassiveStartupIT extends AbstractHATest { | ||
|
||
@Before | ||
@Override | ||
public void setUp() throws Exception { | ||
System.out.println(" => [" + testName.getMethodName() + "] " + getClass().getSimpleName() + ".setUp()"); | ||
|
||
// this sequence is so tha twe can have a stripe of 2 servers bu starting with only 1 active | ||
// galvan does not have an easier way to do that | ||
voltron.getClusterControl().waitForActive(); | ||
voltron.getClusterControl().waitForRunningPassivesInStandby(); | ||
voltron.getClusterControl().terminateOnePassive(); | ||
|
||
commonSetUp(voltron); | ||
tmsAgentService.readMessages(); | ||
} | ||
|
||
@Test | ||
public void get_notifications_when_passive_joins() throws Exception { | ||
put(0, "clients", "client1", "Mat"); | ||
|
||
// start a passive after management is connected to active | ||
voltron.getClusterControl().startOneServer(); | ||
voltron.getClusterControl().waitForRunningPassivesInStandby(); | ||
|
||
assertThat(get(1, "clients", "client1"), equalTo("Mat")); | ||
|
||
Server active = tmsAgentService.readTopology().serverStream().filter(Server::isActive).findFirst().get(); | ||
Server passive = tmsAgentService.readTopology().serverStream().filter(server -> !server.isActive()).findFirst().get(); | ||
assertThat(active.getState(), equalTo(Server.State.ACTIVE)); | ||
assertThat(passive.getState(), equalTo(Server.State.PASSIVE)); | ||
|
||
// read messages | ||
List<Message> messages = tmsAgentService.readMessages(); | ||
assertThat(messages.size(), equalTo(13)); | ||
Map<String, List<Message>> map = messages.stream().collect(Collectors.groupingBy(Message::getType)); | ||
assertThat(map.size(), equalTo(2)); | ||
assertThat(map.keySet(), hasItem("TOPOLOGY")); | ||
assertThat(map.keySet(), hasItem("NOTIFICATION")); | ||
assertThat(map.get("NOTIFICATION").size(), equalTo(12)); | ||
|
||
List<ContextualNotification> notifs = map.get("NOTIFICATION").stream() | ||
.flatMap(message -> message.unwrap(ContextualNotification.class).stream()) | ||
.collect(Collectors.toList()); | ||
|
||
// test notifications generated on active from passive "actions" | ||
assertThat( | ||
notifs.stream().map(ContextualNotification::getType).collect(Collectors.toList()), | ||
equalTo(Arrays.asList( | ||
"SERVER_JOINED", | ||
"SERVER_STATE_CHANGED", | ||
"SERVER_ENTITY_CREATED", | ||
"SERVER_ENTITY_CREATED", "ENTITY_REGISTRY_AVAILABLE", | ||
"SERVER_ENTITY_CREATED", "ENTITY_REGISTRY_AVAILABLE", "ENTITY_REGISTRY_UPDATED", | ||
"SERVER_ENTITY_CREATED", "ENTITY_REGISTRY_AVAILABLE", "ENTITY_REGISTRY_UPDATED", | ||
"SERVER_STATE_CHANGED"))); | ||
|
||
// only 1 server in source: passive server | ||
assertThat( | ||
notifs.stream().map(contextualNotification -> contextualNotification.getContext().get(Server.NAME_KEY)).collect(Collectors.toSet()), | ||
equalTo(new HashSet<>(Arrays.asList(passive.getServerName())))); | ||
|
||
// test state transition of passive | ||
assertThat( | ||
Stream.of(1, 11).map(idx -> notifs.get(idx).getAttributes().get("state")).collect(Collectors.toList()), | ||
equalTo(Arrays.asList("SYNCHRONIZING", "PASSIVE"))); | ||
|
||
// wait for SYNC_END message to transit from passive to active | ||
do { | ||
messages = tmsAgentService.readMessages(); | ||
} | ||
while (messages.isEmpty() && !Thread.currentThread().isInterrupted()); | ||
|
||
assertThat(messages.stream() | ||
.filter(message -> message.getType().equals("NOTIFICATION")) | ||
.flatMap(message -> message.unwrap(ContextualNotification.class).stream()) | ||
.map(ContextualNotification::getType) | ||
.collect(Collectors.toList()), | ||
equalTo(Arrays.asList("SYNC_END", "SYNC_END"))); | ||
|
||
assertThat(messages.stream() | ||
.filter(message -> message.getType().equals("NOTIFICATION")) | ||
.flatMap(message -> message.unwrap(ContextualNotification.class).stream()) | ||
.map(contextualNotification -> contextualNotification.getContext().get(Server.NAME_KEY)) | ||
.collect(Collectors.toList()), | ||
equalTo(Arrays.asList(passive.getServerName(), passive.getServerName()))); | ||
} | ||
|
||
} |
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
Oops, something went wrong.