use of com.sleepycat.je.Durability in project qpid-broker-j by apache.
the class MultiNodeTest method testClusterCannotStartWithIntruder.
public void testClusterCannotStartWithIntruder() throws Exception {
// set property explicitly as test requires broker to start to enable check for ERRORED nodes
setSystemProperty(Broker.BROKER_FAIL_STARTUP_WITH_ERRORED_CHILD, String.valueOf(Boolean.FALSE));
int intruderPort = getNextAvailable(Collections.max(_groupCreator.getBdbPortNumbers()) + 1);
String nodeName = "intruder";
String nodeHostPort = _groupCreator.getIpAddressOfBrokerHost() + ":" + intruderPort;
File environmentPathFile = Files.createTempDirectory("qpid-work-intruder").toFile();
try {
environmentPathFile.mkdirs();
ReplicationConfig replicationConfig = new ReplicationConfig(_groupCreator.getGroupName(), nodeName, nodeHostPort);
replicationConfig.setHelperHosts(_groupCreator.getHelperHostPort());
EnvironmentConfig envConfig = new EnvironmentConfig();
envConfig.setAllowCreate(true);
envConfig.setTransactional(true);
envConfig.setDurability(new Durability(Durability.SyncPolicy.SYNC, Durability.SyncPolicy.WRITE_NO_SYNC, Durability.ReplicaAckPolicy.SIMPLE_MAJORITY));
final String currentThreadName = Thread.currentThread().getName();
try (ReplicatedEnvironment intruder = new ReplicatedEnvironment(environmentPathFile, replicationConfig, envConfig)) {
LOGGER.debug("Intruder started");
} finally {
Thread.currentThread().setName(currentThreadName);
}
for (int port : _groupCreator.getBrokerPortNumbersForNodes()) {
_groupCreator.awaitNodeToAttainAttributeValue(port, port, BDBHAVirtualHostNode.STATE, State.ERRORED.name());
}
_groupCreator.stopCluster();
_groupCreator.startCluster();
for (int port : _groupCreator.getBrokerPortNumbersForNodes()) {
_groupCreator.awaitNodeToAttainAttributeValue(port, port, BDBHAVirtualHostNode.STATE, State.ERRORED.name());
}
} finally {
FileUtils.delete(environmentPathFile, true);
}
}
use of com.sleepycat.je.Durability in project qpid-broker-j by apache.
the class BDBHAVirtualHostNodeTest method testIntruderProtectionInManagementMode.
public void testIntruderProtectionInManagementMode() throws Exception {
int nodePortNumber = _portHelper.getNextAvailable();
int intruderPortNumber = _portHelper.getNextAvailable();
String helperAddress = "localhost:" + nodePortNumber;
String groupName = "group";
String nodeName = "node";
Map<String, Object> nodeAttributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, nodePortNumber);
BDBHAVirtualHostNode<?> node = _helper.createAndStartHaVHN(nodeAttributes);
final CountDownLatch stopLatch = new CountDownLatch(1);
ConfigurationChangeListener listener = new AbstractConfigurationChangeListener() {
@Override
public void stateChanged(ConfiguredObject<?> object, State oldState, State newState) {
if (newState == State.ERRORED) {
stopLatch.countDown();
}
}
};
node.addChangeListener(listener);
File environmentPathFile = new File(_helper.getMessageStorePath() + File.separator + "intruder");
Durability durability = Durability.parse((String) nodeAttributes.get(BDBHAVirtualHostNode.DURABILITY));
joinIntruder(intruderPortNumber, "intruder", groupName, helperAddress, durability, environmentPathFile);
LOGGER.debug("Permitted and intruder nodes are created");
assertTrue("Intruder protection was not triggered during expected timeout", stopLatch.await(10, TimeUnit.SECONDS));
LOGGER.debug("Master node transited into ERRORED state due to intruder protection");
when(_helper.getBroker().isManagementMode()).thenReturn(true);
LOGGER.debug("Starting node in management mode");
final CountDownLatch stateChangeLatch = new CountDownLatch(1);
final CountDownLatch roleChangeLatch = new CountDownLatch(1);
node.addChangeListener(new AbstractConfigurationChangeListener() {
@Override
public void stateChanged(final ConfiguredObject<?> object, final State oldState, final State newState) {
if (newState == State.ERRORED) {
stateChangeLatch.countDown();
}
}
@Override
public void attributeSet(final ConfiguredObject<?> object, final String attributeName, final Object oldAttributeValue, final Object newAttributeValue) {
if (BDBHAVirtualHostNode.ROLE.equals(attributeName) && NodeRole.DETACHED.equals(NodeRole.DETACHED)) {
roleChangeLatch.countDown();
}
}
});
node.start();
LOGGER.debug("Node is started");
// verify that intruder detection is triggered after restart and environment is closed
assertTrue("Node state was not set to ERRORED", stateChangeLatch.await(10, TimeUnit.SECONDS));
assertTrue("Node role was not set to DETACHED", roleChangeLatch.await(10, TimeUnit.SECONDS));
}
use of com.sleepycat.je.Durability in project qpid-broker-j by apache.
the class BDBHAVirtualHostNodeTest method testIntruderConnected.
public void testIntruderConnected() throws Exception {
int node1PortNumber = _portHelper.getNextAvailable();
int node2PortNumber = _portHelper.getNextAvailable();
String helperAddress = "localhost:" + node1PortNumber;
String groupName = "group";
String nodeName = "node1";
Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber);
BDBHAVirtualHostNode<?> node1 = _helper.createAndStartHaVHN(node1Attributes);
final CountDownLatch stopLatch = new CountDownLatch(1);
ConfigurationChangeListener listener = new AbstractConfigurationChangeListener() {
@Override
public void stateChanged(ConfiguredObject<?> object, State oldState, State newState) {
if (newState == State.ERRORED) {
stopLatch.countDown();
}
}
};
node1.addChangeListener(listener);
String node2Name = "node2";
File environmentPathFile = new File(_helper.getMessageStorePath() + File.separator + node2Name);
Durability durability = Durability.parse((String) node1Attributes.get(BDBHAVirtualHostNode.DURABILITY));
joinIntruder(node2PortNumber, node2Name, groupName, helperAddress, durability, environmentPathFile);
assertTrue("Intruder protection was not triggered during expected timeout", stopLatch.await(20, TimeUnit.SECONDS));
}
use of com.sleepycat.je.Durability in project qpid-broker-j by apache.
the class BDBHAVirtualHostNodeTest method testNodeCannotStartWithIntruder.
public void testNodeCannotStartWithIntruder() throws Exception {
int nodePortNumber = _portHelper.getNextAvailable();
int intruderPortNumber = _portHelper.getNextAvailable();
String helperAddress = "localhost:" + nodePortNumber;
String groupName = "group";
String nodeName = "node";
Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, nodePortNumber);
BDBHAVirtualHostNode<?> node = _helper.createAndStartHaVHN(node1Attributes);
final CountDownLatch stopLatch = new CountDownLatch(1);
ConfigurationChangeListener listener = new AbstractConfigurationChangeListener() {
@Override
public void stateChanged(ConfiguredObject<?> object, State oldState, State newState) {
if (newState == State.ERRORED) {
stopLatch.countDown();
}
}
};
node.addChangeListener(listener);
File environmentPathFile = new File(_helper.getMessageStorePath() + File.separator + "intruder");
Durability durability = Durability.parse((String) node1Attributes.get(BDBHAVirtualHostNode.DURABILITY));
joinIntruder(intruderPortNumber, "intruder", groupName, helperAddress, durability, environmentPathFile);
assertTrue("Intruder protection was not triggered during expected timeout", stopLatch.await(10, TimeUnit.SECONDS));
final CountDownLatch stateChangeLatch = new CountDownLatch(1);
final CountDownLatch roleChangeLatch = new CountDownLatch(1);
node.addChangeListener(new AbstractConfigurationChangeListener() {
@Override
public void stateChanged(final ConfiguredObject<?> object, final State oldState, final State newState) {
if (newState == State.ERRORED) {
stateChangeLatch.countDown();
}
}
@Override
public void attributeSet(final ConfiguredObject<?> object, final String attributeName, final Object oldAttributeValue, final Object newAttributeValue) {
if (BDBHAVirtualHostNode.ROLE.equals(attributeName) && NodeRole.DETACHED.equals(NodeRole.DETACHED)) {
roleChangeLatch.countDown();
}
}
});
// Try top re start the ERRORED node and ensure exception is thrown
try {
node.start();
fail("Restart of node should have thrown exception");
} catch (IllegalStateException ise) {
assertEquals("Unexpected exception when restarting node post intruder detection", "Intruder node detected: " + "localhost:" + intruderPortNumber, ise.getMessage());
}
// verify that intruder detection is triggered after restart and environment is closed
assertTrue("Node state was not set to ERRORED", stateChangeLatch.await(10, TimeUnit.SECONDS));
assertTrue("Node role was not set to DETACHED", roleChangeLatch.await(10, TimeUnit.SECONDS));
}
use of com.sleepycat.je.Durability in project qpid-broker-j by apache.
the class ReplicatedEnvironmentFacadeTest method testSetMessageStoreDurability.
public void testSetMessageStoreDurability() throws Exception {
ReplicatedEnvironmentFacade master = createMaster();
assertEquals("Unexpected message store durability", new Durability(Durability.SyncPolicy.NO_SYNC, Durability.SyncPolicy.NO_SYNC, Durability.ReplicaAckPolicy.SIMPLE_MAJORITY), master.getRealMessageStoreDurability());
assertEquals("Unexpected durability", TEST_DURABILITY, master.getMessageStoreDurability());
assertTrue("Unexpected coalescing sync", master.isCoalescingSync());
master.setMessageStoreDurability(Durability.SyncPolicy.WRITE_NO_SYNC, Durability.SyncPolicy.SYNC, Durability.ReplicaAckPolicy.ALL);
assertEquals("Unexpected message store durability", new Durability(Durability.SyncPolicy.WRITE_NO_SYNC, Durability.SyncPolicy.SYNC, Durability.ReplicaAckPolicy.ALL), master.getRealMessageStoreDurability());
assertFalse("Coalescing sync committer is still running", master.isCoalescingSync());
}
Aggregations