コード例 #1
0
  @Test
  public void testServiceWithDSLLogger() throws Exception {
    final Logger logger = Logger.getLogger(BaseDslScript.class.getName());
    final DSLLoggerHandler handler = new DSLLoggerHandler();
    logger.addHandler(handler);

    final File dir = new File(TEST_PARSING_RESOURCE_BASE + "logger");
    final Service service = ServiceReader.getServiceFromDirectory(dir).getService();
    Assert.assertNotNull(service);

    Assert.assertTrue(
        "Println logger not found", handler.getMessages().contains("println logger call"));
    Assert.assertTrue(
        "Print logger not found", handler.getMessages().contains("print logger call"));
    Assert.assertTrue(
        "Class println not found", handler.getMessages().contains("Test Class println"));
    Assert.assertTrue("Class print not found", handler.getMessages().contains("Test Class print"));

    Assert.assertFalse(
        "preInstall event message appeared before expected",
        handler.getMessages().contains("This is the preInstall event"));

    final ExecutableDSLEntry preInstall = service.getLifecycle().getPreInstall();
    final ClosureExecutableEntry preInstallClosureEntry = (ClosureExecutableEntry) preInstall;
    preInstallClosureEntry.getCommand().call();

    Assert.assertTrue(
        "preInstall event message not found",
        handler.getMessages().contains("This is the preInstall event"));
  }
コード例 #2
0
  /** @throws Exception . */
  @Test
  public void testExternalScalingRules() throws Exception {
    final File dir = new File(TEST_PARSING_RESOURCE_PATH2 + "loadScalingRules");

    final Service service = ServiceReader.getServiceFromDirectory(dir).getService();

    Assert.assertTrue(service.getScalingRules().size() > 0);
  }
コード例 #3
0
  @Test
  public void testInvalidProperties() {

    final File serviceDir = new File(TEST_PARSING_RESOURCE_BASE + "invalidProperties");

    try {
      Service service = ServiceReader.getServiceFromDirectory(serviceDir).getService();
      System.out.println(service);
      System.out.println("retries: " + service.getRetries());
      Assert.fail("Expected parsing to fail");
    } catch (Exception e) {
      Assert.assertTrue("Invalid error message", e.getMessage().contains("Error converting from"));
    }
  }
コード例 #4
0
  /**
   * @throws DSLException .
   * @throws UnknownHostException .
   */
  @Test
  public void testDebugParsing() throws DSLException, UnknownHostException {
    final File testDebugPath = new File(TEST_PARSING_DEBUG);

    final Service service = ServiceReader.getServiceFromDirectory(testDebugPath).getService();

    // Assert.assertEquals("test features", service.getName());
    // Assert.assertEquals("http://"
    // + InetAddress.getLocalHost().getHostName() + ":8080",
    // service.getUrl());
    // final ServiceLifecycle lifecycle = service.getLifecycle();
    //
    // Assert.assertNotNull(lifecycle.getStart());
    // Assert.assertNotNull(lifecycle.getPostStart());
    // Assert.assertNotNull(lifecycle.getPreStop());
    // System.out.println(service);
  }
コード例 #5
0
 /**
  * Verifies the service configuration is valid.
  *
  * @param serviceFolder The Folder holding the service configuration files
  * @throws CLIException Reporting a failure to find or parse the configuration files
  */
 private void isServiceLifecycleNotNull(final File serviceFolder) throws CLIException {
   Service service;
   try {
     final File serviceFileDir = new File(serviceFolder, "ext");
     service =
         ServiceReader.getServiceFromDirectory(
                 serviceFileDir, CloudifyConstants.DEFAULT_APPLICATION_NAME)
             .getService();
     if (service.getLifecycle() == null) {
       throw new CLIException(getFormattedMessage("test_recipe_service_lifecycle_missing"));
     }
   } catch (final FileNotFoundException e) {
     logger.log(Level.SEVERE, "Service configuration file not found " + e.getMessage(), e);
     throw new CLIException("Failed to locate service configuration file. " + e.getMessage(), e);
   } catch (final PackagingException e) {
     logger.log(Level.SEVERE, "Packaging failed: " + e.getMessage(), e);
     e.printStackTrace();
     throw new CLIException("Packaging failed: " + e.getMessage(), e);
   } catch (final DSLException e) {
     logger.log(Level.SEVERE, "DSL Parsing failed: " + e.getMessage(), e);
     e.printStackTrace();
     throw new CLIException("Packaging failed: " + e.getMessage(), e);
   }
 }