| | |
| | | @SuppressWarnings("javadoc") |
| | | public class AssuredReplicationPluginTest extends ReplicationTestCase |
| | | { |
| | | |
| | | public class MonitorAssertions |
| | | { |
| | | |
| | | private Map<String, Long> attributeValues = new HashMap<>(); |
| | | |
| | | public MonitorAssertions(DN baseDN) throws Exception |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Before starting the tests configure some stuff. |
| | | */ |
| | | /** Before starting the tests configure some stuff. */ |
| | | @BeforeClass |
| | | @Override |
| | | public void setUp() throws Exception |
| | |
| | | addEntry(TestCaseUtils.entryFromLdifString(topEntry)); |
| | | } |
| | | |
| | | /** |
| | | * Add an entry in the database. |
| | | */ |
| | | /** Add an entry in the database. */ |
| | | private void addEntry(Entry entry) throws Exception |
| | | { |
| | | debugInfo("AddEntry " + entry.getName()); |
| | |
| | | */ |
| | | private class FakeReplicationServer extends Thread |
| | | { |
| | | |
| | | private ServerSocket listenSocket; |
| | | private boolean shutdown; |
| | | private Session session; |
| | |
| | | this.isAssured = assured; |
| | | } |
| | | |
| | | /** |
| | | * Starts the fake RS, expecting and testing the passed scenario. |
| | | */ |
| | | /** Starts the fake RS, expecting and testing the passed scenario. */ |
| | | public void start(int scenario) |
| | | { |
| | | gen = new CSNGenerator(3, 0L); |
| | |
| | | start(); |
| | | } |
| | | |
| | | /** |
| | | * Wait for DS connections. |
| | | */ |
| | | /** Wait for DS connections. */ |
| | | @Override |
| | | public void run() |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Shutdown the Replication Server service and all its connections. |
| | | */ |
| | | /** Shutdown the Replication Server service and all its connections. */ |
| | | public void shutdown() |
| | | { |
| | | if (shutdown) |
| | |
| | | { |
| | | { |
| | | // Receive server start |
| | | ServerStartMsg serverStartMsg = (ServerStartMsg) session.receive(); |
| | | ServerStartMsg serverStartMsg = waitForSpecificMsg(session, ServerStartMsg.class); |
| | | |
| | | baseDN = serverStartMsg.getBaseDN(); |
| | | serverState = serverStartMsg.getServerState(); |
| | |
| | | session.stopEncryption(); |
| | | } |
| | | |
| | | // Read start session or stop |
| | | ReplicationMsg msg = session.receive(); |
| | | if (msg instanceof StopMsg){ |
| | | // Disconnection of DS looking for best server |
| | |
| | | return scenarioExecuted; |
| | | } |
| | | |
| | | /** |
| | | * Handle client connection then call code specific to configured test. |
| | | */ |
| | | /** Handle client connection then call code specific to configured test. */ |
| | | private void handleClientConnection() throws Exception |
| | | { |
| | | debugInfo("handleClientConnection " + testcase + " " + scenario); |
| | |
| | | */ |
| | | private AckMsg sendAssuredAddMsg(Entry entry, String parentUid) throws Exception |
| | | { |
| | | { |
| | | AddMsg addMsg = |
| | | new AddMsg(gen.newCSN(), entry.getName(), UUID.randomUUID().toString(), |
| | | parentUid, |
| | | entry.getObjectClassAttribute(), |
| | | entry.getAttributes(), null ); |
| | | AddMsg addMsg = new AddMsg( |
| | | gen.newCSN(), entry.getName(), UUID.randomUUID().toString(), |
| | | parentUid, entry.getObjectClassAttribute(), entry.getAttributes(), null); |
| | | |
| | | // Send add message in assured mode |
| | | addMsg.setAssured(isAssured); |
| | | addMsg.setAssuredMode(assuredMode); |
| | | addMsg.setSafeDataLevel(safeDataLevel); |
| | | session.publish(addMsg); |
| | | // Send add message in assured mode |
| | | addMsg.setAssured(isAssured); |
| | | addMsg.setAssuredMode(assuredMode); |
| | | addMsg.setSafeDataLevel(safeDataLevel); |
| | | session.publish(addMsg); |
| | | |
| | | // Read and return matching ack |
| | | return (AckMsg)session.receive(); |
| | | } |
| | | return waitForSpecificMsg(session, AckMsg.class); |
| | | } |
| | | |
| | | /** |
| | | * Read the coming update and check parameters are not assured. |
| | | */ |
| | | /** Read the coming update and check parameters are not assured. */ |
| | | private void executeNotAssuredScenario() throws Exception |
| | | { |
| | | checkAssuredParametersOnReceivedUpdateMsg(); |
| | |
| | | scenarioExecuted = true; |
| | | } |
| | | |
| | | /** |
| | | * Read the coming update and make the client time out by not sending back |
| | | * the ack. |
| | | */ |
| | | /** Read the coming update and make the client time out by not sending back the ack. */ |
| | | private void executeTimeoutScenario() throws Exception |
| | | { |
| | | checkAssuredParametersOnReceivedUpdateMsg(); |
| | |
| | | // blocked at least for the programmed timeout time. |
| | | } |
| | | |
| | | /** |
| | | * Read the coming update, sleep some time then send back an ack. |
| | | */ |
| | | /** Read the coming update, sleep some time then send back an ack. */ |
| | | private void executeNoTimeoutScenario() throws Exception |
| | | { |
| | | UpdateMsg updateMsg = checkAssuredParametersOnReceivedUpdateMsg(); |
| | |
| | | return updateMsg; |
| | | } |
| | | |
| | | /** |
| | | * Read the coming safe read mode updates and send back acks with errors. |
| | | */ |
| | | /** Read the coming safe read mode updates and send back acks with errors. */ |
| | | private void executeSafeReadManyErrorsScenario() throws Exception |
| | | { |
| | | // Read first update |
| | |
| | | scenarioExecuted = true; |
| | | } |
| | | |
| | | /** |
| | | * Read the coming safe data mode updates and send back acks with errors. |
| | | */ |
| | | /** Read the coming safe data mode updates and send back acks with errors. */ |
| | | private void executeSafeDataManyErrorsScenario() throws Exception |
| | | { |
| | | // Read first update |
| | |
| | | // let timeout occur |
| | | scenarioExecuted = true; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * Return various group id values. |
| | | */ |
| | | /** Return various group id values. */ |
| | | @DataProvider(name = "rsGroupIdProvider") |
| | | private Object[][] rsGroupIdProvider() |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Tests parameters sent in session handshake and updates, when not using |
| | | * assured replication. |
| | | */ |
| | | /** Tests parameters sent in session handshake and updates, when not using assured replication. */ |
| | | @Test |
| | | public void testNotAssuredSession() throws Exception |
| | | { |
| | | |
| | | String testcase = "testNotAssuredSession"; |
| | | try |
| | | { |
| | |
| | | // Wait for connection of domain to RS |
| | | waitForConnectionToRs(testcase, replicationServer); |
| | | |
| | | /* |
| | | * Send an update from the RS and get the ack |
| | | */ |
| | | /* Send an update from the RS and get the ack */ |
| | | |
| | | // Make the RS send an assured add message |
| | | String entryStr = "dn: ou=assured-sr-reply-entry," + SAFE_READ_DN + "\n" + |
| | |
| | | return; |
| | | } |
| | | |
| | | /* |
| | | * Send un update with error from the RS and get the ack with error |
| | | */ |
| | | /* Send an update with error from the RS and get the ack with error */ |
| | | |
| | | // Make the RS send a not possible assured add message |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Delete an entry from the database. |
| | | */ |
| | | /** Delete an entry from the database. */ |
| | | private void deleteEntry(String dn) throws Exception |
| | | { |
| | | DN realDN = DN.valueOf(dn); |
| | |
| | | SearchResultEntry entry = op.getSearchEntries().getFirst(); |
| | | assertNotNull(entry); |
| | | |
| | | /* |
| | | * Find the multi valued attribute matching the requested assured mode |
| | | */ |
| | | /* Find the multi valued attribute matching the requested assured mode */ |
| | | String assuredAttr; |
| | | switch(assuredMode) |
| | | { |