@BeforeMethod
  public void setUp() throws Exception {
    cleanupDB();
    m_mockStoreManager = EasyMock.createMock(IActiveMailboxStoreManager.class);
    ICustomerManager customerMgrMock = new CustomerManagerMock();
    IIslandManager islandMgrMock = createNiceMock(IIslandManager.class);
    int islandId =
        0; // needs to match value for feed/search passed into TestUtils.createCustomer() call to
    // customer manager
    boolean provisioned = true; // needs to be provisioned-enabled
    Island island =
        new Island(islandId, "fooIsland", null, provisioned, false, "fooPlatform", "fooSchema");
    expect(islandMgrMock.getIsland(islandId)).andReturn(island).anyTimes();
    expect(islandMgrMock.isValidIsland(islandId)).andReturn(true).anyTimes();
    replay(islandMgrMock);
    ManagementContainerInjector.getInjector()
        .withService(islandMgrMock, getClass().getName())
        .withService(customerMgrMock, getClass().getName());

    m_customer =
        TestUtils.createActiveMailboxTestCustomer(
            Capabilities.ActiveMailboxSupport.AM_CUSTOMER_ENCRYPTION);
    assertNotNull("Customer should have been created", m_customer);

    TestUtils.cleanupTestUsers(m_customer.getCustID());

    m_user = TestUtils.createUser(m_customer, "user-1", "1", "password");
    assertNotNull("User should have been created", m_user);
  }
Example #2
0
 @BeforeClass
 protected void setUp() throws Exception {
   super.setUp();
   // Be sure your classpath points to the parent of the WEB-INF directory
   setConfigFile("/WEB-INF/struts-config.xml");
   setInitParameter("validating", "false");
   m_customer = TestUtils.createTestCustomer();
   m_user = TestUtils.createUser(m_customer, "system");
 }
Example #3
0
 protected CustomerTopology createTopology() throws Exception {
   Customer customer =
       ManagementContainer.getInstance()
           .getCustomerManager()
           .getCustomer(getJspTestUtils().getCustId());
   return TestUtils.makeSingleGroupTopology(customer, 1, ExchangeRole.MailboxRole.getFlag());
 }
  @Test
  public void testReset() throws Exception {
    final HttpServletRequest request = TestUtils.createRequest();

    Runnable doReset =
        new Runnable() {
          @Override
          public void run() {
            CachedTransitionToken.reset(request);
            testResetA.set(testResetB.incrementAndGet());
          }
        };

    Thread stateThread = new Thread(doReset);
    stateThread.start();
    stateThread.join(10000);
    Assert.assertEquals(testResetA.get(), 1);

    CachedTransitionToken.start(request);

    doReset =
        new Runnable() {
          @Override
          public void run() {
            CachedTransitionToken.reset(request);
            testResetA.set(testResetB.incrementAndGet());
          }
        };

    stateThread = new Thread(doReset);
    stateThread.start();
    testResetB.set(100);
    CachedTransitionToken.end(request);
    stateThread.join(10000);
    Assert.assertEquals(testResetA.get(), 101);
  }
  @Test
  public void testBackupFailure() throws Exception {
    IPartitionManager pm = ManagementContainer.getInstance().getPartitionManager();

    m_part.setAccessibleRemotely(true);
    pm.updatePartition(m_part);
    m_part = pm.getPartition(TEST_PID);

    Customer cust =
        TestUtils.createActiveMailboxTestCustomer(Capabilities.ActiveMailboxSupport.ARCHIVE);
    try {
      MockMessageImporter mock = new MockMessageImporter(getClass().getSimpleName());
      PartitionStoreStage stg =
          new PartitionStoreStage(mock) {
            public void finish() {
              super.finish();
              ((StatComponent) m_importer.getStatComponent()).stop();
            }
          };
      MockStageController ctrl = new MockStageController("test");
      stg.setStageController(ctrl);

      assertEquals(0, mock.getNumFailedMessages());
      assertEquals(0, mock.getNumSucceededMessages());
      // Partition dummyPart = new Partition(10, "sdcvsdv");

      File backupSubDir = new File(m_part.getStorageDirectory(), Partition.BACKUP_SUBDIR);

      Pair<Partition, List<IMessageContext>> buffer =
          new Pair<Partition, List<IMessageContext>>(
              m_part, generateMockMessageContext(10000, 10, cust));

      stg.process(buffer);

      // Nothing should have failed
      assertEquals(0, mock.getNumFailedMessages());
      assertEquals(10, ctrl.getOutputCount());

      assertTrue(backupSubDir.exists());

      // Stop backup writers, delete backup directory and then make sure everything works when we
      // start back up
      Utils.finishBackupWriters();

      FileUtils.deleteDirectory(backupSubDir);

      assertFalse(backupSubDir.exists());
      Utils.startBackupWriters();

      ctrl.resetOutputCount();
      buffer =
          new Pair<Partition, List<IMessageContext>>(
              m_part, generateMockMessageContext(100000, 10, cust));

      stg.process(buffer);

      // Nothing should have failed
      assertEquals(0, mock.getNumFailedMessages());
      assertEquals(10, ctrl.getOutputCount());

      assertTrue(backupSubDir.exists());
      stg.finish();
    } finally {
      TestUtils.quietDeleteCustomer(cust);
    }
  }
 @BeforeClass
 public void beforeClass() throws Exception {
   TestUtils.cleanupPartition(TEST_PID);
   TestUtils.cleanupPartition(TEST_PID2);
 }
  /**
   * Validates that the stage properly identifies when a SNAException has occured on a message
   * multiple times consecutively and properly fails the message
   *
   * @throws Exception on error
   */
  @Test
  public void testServiceNotAvailableExceptionHandling() throws Exception {
    MockMessageImporter mock = new MockMessageImporter(getClass().getSimpleName());
    PartitionStoreStage stg =
        new PartitionStoreStage(mock) {
          public void finish() {
            super.finish();
            ((StatComponent) m_importer.getStatComponent()).stop();
          }
        };
    stg.setStageController(new MockStageController("test"));

    final IPartitionProxy partitionProxy = createNiceMock(IPartitionProxy.class);

    assertEquals(0, mock.getNumFailedMessages());
    assertEquals(0, mock.getNumSucceededMessages());

    String path = m_tmpDir + "/storage";
    Partition dummyPart = null;
    try {

      int messageBufferSize = 10;
      Customer cust =
          TestUtils.createActiveMailboxTestCustomer(Capabilities.ActiveMailboxSupport.ARCHIVE);
      List<IMessageContext> msgs = generateMockMessageContext(100, messageBufferSize, cust);

      // force an exception on any call to storeMessages
      expect(partitionProxy.storeMessages(msgs))
          .andThrow(new IPartitionProxy.ServiceNotAvailableException(new Exception()))
          .anyTimes();
      replay(partitionProxy);

      PartitionManager pm =
          new PartitionManager(
              ManagementContainer.getInstance().getPool(ManagementContainer.AM_POOL_NAME)) {
            @Override
            public IPartitionProxy getContentProxy(int id) {
              return partitionProxy;
            }
          };
      PartitionManagerTest.preparePartitionManager(pm);
      stg.setPartitionManager(pm);
      dummyPart = pm.initializePartition(TEST_PID2, "localhost", path, null);
      s_logger.debug("Dummy Partition: " + dummyPart + " (type: " + dummyPart.getClass() + ")");
      Pair<Partition, List<IMessageContext>> buffer =
          new Pair<Partition, List<IMessageContext>>(dummyPart, msgs);

      for (int i = 0; i < stg.getErrorThreshold(); i++) {
        stg.process(buffer);
        assertEquals("Wrong number of failed messages.", 0, mock.getNumFailedMessages());
        assertEquals("Wrong number of succeeded messages.", 0, mock.getNumSucceededMessages());
      }

      stg.process(buffer);
      assertEquals(
          "Wrong number of failed messages", messageBufferSize, mock.getNumFailedMessages());
      assertEquals("Wrong number of succeeded messages", 0, mock.getNumSucceededMessages());

      // Test that errors must come from the same importer before they can fail a message
      mock = new MockMessageImporter(getClass().getSimpleName());
      MockMessageImporter mock2 = new MockMessageImporter(getClass().getSimpleName());
      PartitionStoreStage stg2 = new PartitionStoreStage(mock2);
      stg2.setPartitionManager(pm);
      stg2.setStageController(new MockStageController("test"));
      stg.finish();
      stg = new PartitionStoreStage(mock);
      stg.setStageController(new MockStageController("test"));
      stg.setPartitionManager(pm);

      buffer = new Pair<Partition, List<IMessageContext>>(dummyPart, msgs);

      // Send the message buffer through Threshold - 1 times using importer 1 and then 1 time with
      // importer 2 which should not result in failure
      // Then send the messages through importer 1 again Threshold times and verify it only fails
      // the messages once we have reached threshold
      for (int i = 0; i < stg.getErrorThreshold(); i++) {
        stg.process(buffer);
        assertEquals(0, mock.getNumFailedMessages());
        assertEquals(0, mock.getNumSucceededMessages());
      }

      stg2.process(buffer);
      assertEquals(0, mock2.getNumFailedMessages());
      assertEquals(0, mock2.getNumSucceededMessages());
      assertEquals(0, mock.getNumFailedMessages());
      assertEquals(0, mock.getNumSucceededMessages());
      for (int i = 0; i < stg.getErrorThreshold(); i++) {
        stg.process(buffer);
        assertEquals(0, mock.getNumFailedMessages());
        assertEquals(0, mock.getNumSucceededMessages());
      }

      stg.process(buffer);
      assertEquals(messageBufferSize, mock.getNumFailedMessages());
      assertEquals(0, mock.getNumSucceededMessages());

      // Now validate that age comes into play as well
      mock = new MockMessageImporter(getClass().getSimpleName());
      stg.finish();
      stg = new PartitionStoreStage(mock);
      stg.setStageController(new MockStageController("test"));
      stg.setErrorAgeThreshold(5000);
      stg.setPartitionManager(pm);
      buffer =
          new Pair<Partition, List<IMessageContext>>(
              m_part, generateMockMessageContext(1000, messageBufferSize, cust));

      for (int i = 0; i < stg.getErrorThreshold(); i++) {
        stg.process(buffer);
        assertEquals("Wrong number of failed messages", 0, mock.getNumFailedMessages());
        assertEquals("Wrong number of succeeded messages", 0, mock.getNumSucceededMessages());
      }

      // Thread.sleep( 6000 );
      stg.process(buffer);
      stg.finish();
      stg2.finish();
      assertEquals(0, mock.getNumFailedMessages());
      assertEquals(0, mock.getNumSucceededMessages());
    } finally {

    }
  }
  @Test
  public void testFailureTracking() throws Exception {
    final IPartitionProxy partitionProxy = createNiceMock(IPartitionProxy.class);
    final IPartitionProxy partitionProxy2 = createNiceMock(IPartitionProxy.class);
    long msgId = 2L;
    IFailureTrackingManager failMgr = ManagementContainer.getInstance().getFailureTrackingManager();
    StorageImporter importer = new MockStorageImporter();
    Customer customer = TestUtils.createTestCustomer();
    try {
      PartitionStoreStage stage = new PartitionStoreStage(importer);
      Pipeline pipeline =
          PipelineBuilder.start(
                  ManagementContainer.getInstance().getConfiguration(),
                  MessageImporter.PIPELINE_CONFIG_SECTION)
              .singleton("store-stage", stage)
              .get();
      File envelopeFile =
          File.createTempFile(
              "PartitionStoreTest", "test", ManagementContainer.getInstance().getNfsRoot());
      IMessageContext msgCtx = new MessageContext(envelopeFile, null);
      msgCtx.setCustomer(customer);
      msgCtx.setIndexMessage(true);
      msgCtx.setInternalId(msgId);
      msgCtx.setPartition(m_part);
      msgCtx.setPartitionID(m_part.getId());
      Collection<IMessageContext> msgs = Collections.singletonList(msgCtx);
      Collection<IMessageContext> emptyResult = Collections.emptyList();

      expect(partitionProxy.storeMessages(msgs)).andReturn(emptyResult).anyTimes();
      replay(partitionProxy);

      PartitionManager pm =
          new PartitionManager(
              ManagementContainer.getInstance().getPool(ManagementContainer.AM_POOL_NAME)) {
            @Override
            public IPartitionProxy getContentProxy(int id) {
              return partitionProxy;
            }
          };
      PartitionManagerTest.preparePartitionManager(pm);
      stage.setPartitionManager(pm);

      FailureRecord failureRecord =
          FailureTrackingHelper.buildFailureRecord(msgCtx, FailureCategory.STORAGE, null, null);
      failureRecord.setStoredOnPartition(false);
      failMgr.insertMessageFailure(failureRecord);
      msgCtx.setInternalFailureId(msgId);
      pipeline.process(
          new Pair<Partition, List<IMessageContext>>(m_part, Collections.singletonList(msgCtx)));
      failureRecord = failMgr.getFailureRecord(msgId);
      assertTrue("Should find stored on partition to be true", failureRecord.isStoredOnPartition());
      Map<String, String> props = msgCtx.readEnvelope();
      assertTrue(
          "envelope should contain failure ID",
          props.containsKey(ParseEnvelopeStage.INTERNAL_MESSAGE_FAILURE_ID));
      assertEquals(
          "message ID in envelope should match permanent ID",
          String.valueOf(msgId),
          props.get(ParseEnvelopeStage.INTERNAL_MESSAGE_FAILURE_ID));

      // confirm that transient ID gets set back to real ID of message
      // remove the existing failure record
      failMgr.removeFailure(msgId);
      // change the ID
      msgCtx.setInternalFailureId(msgId + 1);
      msgCtx.setInternalId(msgId + 1);
      // insert the new failure record
      failureRecord =
          FailureTrackingHelper.buildFailureRecord(msgCtx, FailureCategory.STORAGE, null, null);
      failMgr.insertMessageFailure(failureRecord);
      // old record should be gone
      failureRecord = failMgr.getFailureRecord(msgId);
      assertNull("Should no longer find the failure record with permanent ID", failureRecord);
      // check that the new record can be fetched
      failureRecord = failMgr.getFailureRecord(msgId + 1);
      assertNotNull("Should find transient ID failure record", failureRecord);
      msgCtx.appendToEnvelope(ParseEnvelopeStage.INTERNAL_MESSAGE_FAILURE_ID, msgId + 1);
      props = msgCtx.readEnvelope();
      assertTrue(
          "envelope should contain failure ID",
          props.containsKey(ParseEnvelopeStage.INTERNAL_MESSAGE_FAILURE_ID));
      assertEquals(
          "message ID in envelope should match permanent ID",
          String.valueOf(msgId + 1),
          props.get(ParseEnvelopeStage.INTERNAL_MESSAGE_FAILURE_ID));

      // now assign back the permanent ID and process through the pipeline
      msgCtx.setInternalId(msgId);
      pipeline.process(
          new Pair<Partition, List<IMessageContext>>(m_part, Collections.singletonList(msgCtx)));

      failureRecord = failMgr.getFailureRecord(msgId + 1);
      assertNull("Should not find any record based on transient message ID", failureRecord);
      failureRecord = failMgr.getFailureRecord(msgId);
      assertNotNull("Should find failure record for permanent ID", failureRecord);
      assertTrue("Should find stored on partition to be true", failureRecord.isStoredOnPartition());
      // envelope should now reflect permanent ID
      props = msgCtx.readEnvelope();
      assertTrue(
          "envelope should contain failure ID",
          props.containsKey(ParseEnvelopeStage.INTERNAL_MESSAGE_FAILURE_ID));
      assertEquals(
          "message ID in envelope should match permanent ID",
          String.valueOf(msgId),
          props.get(ParseEnvelopeStage.INTERNAL_MESSAGE_FAILURE_ID));

      // confirm that state does not change on failure
      // force an exception on any call to storeMessages
      pm =
          new PartitionManager(
              ManagementContainer.getInstance().getPool(ManagementContainer.AM_POOL_NAME)) {
            @Override
            public IPartitionProxy getContentProxy(int id) {
              return partitionProxy2;
            }
          };
      PartitionManagerTest.preparePartitionManager(pm);
      stage.setPartitionManager(pm);

      expect(partitionProxy2.storeMessages(msgs))
          .andThrow(new IPartitionProxy.ServiceNotAvailableException(new Exception()))
          .anyTimes();
      replay(partitionProxy2);
      failureRecord.setStoredOnPartition(false);
      failMgr.insertMessageFailure(failureRecord);
      pipeline.process(
          new Pair<Partition, List<IMessageContext>>(m_part, Collections.singletonList(msgCtx)));
      failureRecord = failMgr.getFailureRecord(msgId);
      assertNotNull("Should find the failure record for message", failureRecord);
      assertFalse(
          "Should find stored on partition to be true", failureRecord.isStoredOnPartition());
    } finally {
      importer.stop();
      TestUtils.quietDeleteCustomer(customer);
    }
  }
Example #9
0
  @Test
  public void verifyRetentionPolicyFilterForRetentionHolds() throws Exception {
    // Create a new Test User
    LOGGER.info("Creating a new Test user");
    String currentTime = Long.toString(System.currentTimeMillis());
    String userName = "******" + currentTime;
    String userAddress = userName + "@" + getJspTestUtils().getDomain();
    String password = getJspTestUtils().getPasswd();

    getJspTestUtils().createTestUser(userName, userAddress, password);

    int custId = getJspTestUtils().getCustId();
    LOGGER.info("Test user creation completed:" + userAddress);
    LOGGER.info("Customer Id is: " + Integer.toString(custId));

    // Get Retention policy manager, Reviewer group manager and User manager
    IRetentionPolicyManager mgr = ManagementContainer.getInstance().getRetentionPolicyManager();
    IReviewerGroupManager rgm = ManagementContainer.getInstance().getReviewerGroupManager();
    IUserManager um = ManagementContainer.getInstance().getUserManager();

    // Create Reviewer User set-1  for reviewers
    UserAccount reviewer1 = um.findUserForEmail(getJspTestUtils().m_userAddress);
    SavedUserSet sus1 = new SavedUserSet(custId);
    sus1.addUsers(
        Arrays.asList(
            new SearchConstraint(
                IUserManager.PROP_USERID,
                SearchConstraintOperator.CONSTRAINT_EQUALS,
                String.valueOf(reviewer1.getUserID()))));
    // sus1.setInternal(true);
    sus1.setName("REVIEWERS-1");
    um.saveUserSet(sus1);
    // Create User set-1 for users whose mails will be reviewed by reviewer
    SavedUserSet scope1 = InternalUserSets.getAllUsersSet(custId);
    // scope1.setInternal(true);
    scope1.setName("SCOPE-1");
    um.saveUserSet(scope1);
    // Create Reviewer group-1
    LOGGER.info("Creating Reviewer group reviewerGrp1");
    ReviewerGroup rg1 = rgm.createReviewerGroup(custId, "reviewerGrp1", sus1, scope1, null);
    rgm.updateReviewerGroup(rg1);
    rg1 = rgm.getReviewerGroup(custId, "reviewerGrp1");
    LOGGER.info(
        "Reviewer group creation done. Reviewer group details-> GroupId:"
            + rg1.getGroupID()
            + ";GroupName:"
            + rg1.getGroupName());

    RetentionPolicy qblh1 =
        TestUtils.createPolicy(
            RetentionPolicy.Mode.QUERY_BASED_LEGAL_HOLD,
            custId,
            RetentionPolicy.MAX_RETAIN,
            "QBLH-1",
            RetentionPolicy.HIGHEST_PRIORITY,
            "reviewerGrp1");
    LOGGER.info(
        "Query based legal hold QBLH-1 details-> Policy Id:"
            + qblh1.getId()
            + ";Policy Name:"
            + qblh1.getName());

    // Create Reviewer User set-2 for reviewers
    UserAccount reviewer2 = um.findUserForEmail(userAddress);
    SavedUserSet sus2 = new SavedUserSet(custId);
    sus2.addUsers(
        Arrays.asList(
            new SearchConstraint(
                IUserManager.PROP_USERID,
                SearchConstraintOperator.CONSTRAINT_EQUALS,
                String.valueOf(reviewer2.getUserID()))));
    sus2.setName("REVIEWERS-2");
    um.saveUserSet(sus2);
    // Create User set-2 for users whose mails will be reviewed by reviewer
    SavedUserSet scope2 = InternalUserSets.getAllUsersSet(custId);
    scope2.setName("SCOPE-2");
    um.saveUserSet(scope2);
    // Create Reviewer group-2
    ReviewerGroup rg2 = rgm.createReviewerGroup(custId, "reviewerGrp2", sus2, scope2, null);
    rgm.updateReviewerGroup(rg2);
    rg2 = rgm.getReviewerGroup(custId, "reviewerGrp2");
    LOGGER.info("Reviewer group details:" + rg2.getGroupID() + ";" + rg2.getGroupName());
    RetentionPolicy qblh2 =
        TestUtils.createPolicy(
            RetentionPolicy.Mode.QUERY_BASED_LEGAL_HOLD,
            custId,
            RetentionPolicy.MAX_RETAIN,
            "QBLH-2",
            RetentionPolicy.HIGHEST_PRIORITY,
            "reviewerGrp2");
    LOGGER.info(
        "Query based legal hold QBLH-2 details-> Policy Id:"
            + qblh2.getId()
            + ";Policy Name:"
            + qblh2.getName());

    // Login as reviewer-1  and verify QBLH-1 is visible to reviewer-1 and QBLH-2 is not visible
    LOGGER.info("Logging in as reviewer-1");
    getJspTestUtils()
        .login(getJspTestUtils().m_cappLoginUrl, getJspTestUtils().m_userAddress, password);
    getJspTestUtils().navigateToArchivePage();
    getJspTestUtils().clickLink(By.id("auto_common_nav_search-reviewer"));
    getJspTestUtils().clickLink(By.id("auto_add_filter"));
    getJspTestUtils()
        .clickLink(By.id("auto_filter_dialog_field-button"), By.linkText("Retention Policy"));
    getJspTestUtils().clickLink(By.id("auto_filter_dialog_value_select-button"));
    assertNotNull(
        "Query Based legal hold QBLH-1 is not present for REVIEWERS-1",
        getJspTestUtils().findElement(By.linkText("QBLH-1")));
    assertFalse(
        "Query Based legal hold QBLH-2 is present for REVIEWERS-1",
        getJspTestUtils().isElement(By.linkText("QBLH-2")));
    getJspTestUtils().logout();

    // Login as reviewer-2  and verify QBLH-2 is visible to reviewer-2 and QBLH-1 is not visible
    LOGGER.info("Logging in as reviewer-2");
    getJspTestUtils().login(getJspTestUtils().m_cappLoginUrl, userAddress, password);
    getJspTestUtils().clickLink(By.id("auto_common_nav_search-reviewer"));
    getJspTestUtils().clickLink(By.id("auto_add_filter"));
    getJspTestUtils()
        .clickLink(By.id("auto_filter_dialog_field-button"), By.linkText("Retention Policy"));
    getJspTestUtils().clickLink(By.id("auto_filter_dialog_value_select-button"));
    assertNotNull(
        "Query Based legal hold QBLH-2 is not present for REVIEWERS-2",
        getJspTestUtils().findElement(By.linkText("QBLH-2")));
    assertFalse(
        "Query Based legal hold QBLH-1 is present for REVIEWERS-2",
        getJspTestUtils().isElement(By.linkText("QBLH-1")));
    getJspTestUtils().logout();
  }
 @BeforeClass
 public void beforeClass() throws Exception {
   cleanUp();
   TestUtils.cleanupPartition(PARTITION_ID_1);
   TestUtils.cleanupPartition(PARTITION_ID_2);
 }