コード例 #1
0
  @Test
  public void testApplicationLifecycle() throws InterruptedException {
    // Create local site
    SiteEntity siteEntity = new SiteEntity();
    siteEntity.setSiteId("test_site");
    siteEntity.setSiteName("Test Site");
    siteEntity.setDescription("Test Site for HADOOP_JMX_METRIC_MONITOR");
    siteResource.createSite(siteEntity);
    Assert.assertNotNull(siteEntity.getUuid());

    ApplicationOperations.InstallOperation installOperation =
        new ApplicationOperations.InstallOperation(
            "test_site", "HADOOP_JMX_METRIC_MONITOR", ApplicationEntity.Mode.LOCAL);
    installOperation.setConfiguration(getConf());
    // Install application
    ApplicationEntity applicationEntity =
        applicationResource.installApplication(installOperation).getData();
    // Uninstall application
    applicationResource.uninstallApplication(
        new ApplicationOperations.UninstallOperation(applicationEntity.getUuid()));
    try {
      applicationResource.getApplicationEntityByUUID(applicationEntity.getUuid());
      Assert.fail(
          "Application instance (UUID: "
              + applicationEntity.getUuid()
              + ") should have been uninstalled");
    } catch (Exception ex) {
      // Expected exception
    }
  }
  @Test(expected = IllegalArgumentException.class)
  public void testInsertApplicationEntityFail() {
    SiteEntity siteEntity = new SiteEntity();
    siteEntity.setSiteId("testsiteid");
    siteEntity.setSiteName("testsitename");
    siteEntity.setDescription("testdesc");
    siteEntityService.create(siteEntity);
    ApplicationDesc applicationDesc = new ApplicationDesc();
    applicationDesc.setType("testtype");

    ApplicationEntity applicationEntity = new ApplicationEntity();
    applicationEntity.setSite(siteEntity);
    applicationEntity.setDescriptor(applicationDesc);
    applicationEntity.setMode(ApplicationEntity.Mode.LOCAL);
    applicationEntity.setJarPath("c://");

    applicationEntityService.create(applicationEntity);
    applicationEntityService.create(applicationEntity);
  }
  @Test
  public void testCRUDApplicationEntity() throws SQLException, EntityNotFoundException {

    SiteEntity siteEntity = new SiteEntity();
    siteEntity.setSiteId("testsiteid");
    siteEntity.setSiteName("testsitename");
    siteEntity.setDescription("testdesc");
    siteEntityService.create(siteEntity);
    String siteuuid = siteEntity.getUuid();
    long sitecreateTime = siteEntity.getCreatedTime();
    long sitemodifiedTime = siteEntity.getModifiedTime();
    ApplicationDesc applicationDesc = new ApplicationDesc();
    applicationDesc.setType("testtype");

    ApplicationEntity applicationEntity = new ApplicationEntity();
    applicationEntity.setSite(siteEntity);
    applicationEntity.setDescriptor(applicationDesc);
    applicationEntity.setMode(ApplicationEntity.Mode.LOCAL);
    applicationEntity.setJarPath("c://");

    applicationEntityService.create(applicationEntity);
    String appuuid = applicationEntity.getUuid();
    String appId = applicationEntity.getAppId();
    long createTime = applicationEntity.getCreatedTime();
    long modifiedTime = applicationEntity.getModifiedTime();

    Collection<ApplicationEntity> results = applicationEntityService.findAll();
    Assert.assertEquals(1, results.size());
    ApplicationEntity applicationEntityFromDB =
        applicationEntityService.getBySiteIdAndAppType("testsiteid", "testtype");
    Assert.assertTrue(applicationEntityFromDB != null);
    results = applicationEntityService.findBySiteId("testsiteid");
    Assert.assertEquals(1, results.size());

    applicationEntityFromDB = applicationEntityService.getByUUID(appuuid);

    Assert.assertTrue(applicationEntityFromDB != null);
    applicationEntityFromDB = applicationEntityService.getByUUIDOrAppId(null, appId);

    Assert.assertEquals(siteuuid, applicationEntityFromDB.getSite().getUuid());
    Assert.assertEquals("testsiteid", applicationEntityFromDB.getSite().getSiteId());
    Assert.assertEquals("testsitename", applicationEntityFromDB.getSite().getSiteName());
    Assert.assertEquals("testdesc", applicationEntityFromDB.getSite().getDescription());
    Assert.assertEquals(sitecreateTime, applicationEntityFromDB.getSite().getCreatedTime());
    Assert.assertEquals(sitemodifiedTime, applicationEntityFromDB.getSite().getModifiedTime());

    Assert.assertEquals(appuuid, applicationEntityFromDB.getUuid());
    Assert.assertEquals(appId, applicationEntityFromDB.getAppId());
    Assert.assertEquals("testtype", applicationEntityFromDB.getDescriptor().getType());
    Assert.assertEquals(ApplicationEntity.Mode.LOCAL, applicationEntityFromDB.getMode());
    Assert.assertEquals("c://", applicationEntityFromDB.getJarPath());
    Assert.assertEquals(ApplicationEntity.Status.INITIALIZED, applicationEntityFromDB.getStatus());
    Assert.assertEquals(createTime, applicationEntityFromDB.getCreatedTime());
    Assert.assertEquals(modifiedTime, applicationEntityFromDB.getModifiedTime());
  }
  @Test
  public void testDelApplicationEntity() {
    SiteEntity siteEntity = new SiteEntity();
    siteEntity.setSiteId("testsiteid");
    siteEntity.setSiteName("testsitename");
    siteEntity.setDescription("testdesc");
    siteEntityService.create(siteEntity);
    ApplicationDesc applicationDesc = new ApplicationDesc();
    applicationDesc.setType("testtype");

    ApplicationEntity applicationEntity = new ApplicationEntity();
    applicationEntity.setSite(siteEntity);
    applicationEntity.setDescriptor(applicationDesc);
    applicationEntity.setMode(ApplicationEntity.Mode.LOCAL);
    applicationEntity.setJarPath("c://");
    applicationEntityService.create(applicationEntity);
    Collection<ApplicationEntity> results = applicationEntityService.findAll();
    Assert.assertEquals(1, results.size());
    applicationEntityService.delete(applicationEntity);
    results = applicationEntityService.findAll();
    Assert.assertEquals(0, results.size());
  }