コード例 #1
0
  @Test
  public void addDataSource_replaceExisting() throws Exception {
    client.apply(
        new AddDataSource.Builder(TEST_DATASOURCE_NAME)
            .connectionUrl(VALID_DS_URL)
            .jndiName("java:/jboss/datasources/" + TEST_DATASOURCE_NAME)
            .driverName("h2")
            .usernameAndPassword("creaper", "creaper")
            .build());
    assertTrue("The datasource should be created", ops.exists(TEST_DATASOURCE_ADDRESS));

    client.apply(
        new AddDataSource.Builder(TEST_DATASOURCE_NAME)
            .connectionUrl(VALID_DS_URL)
            .jndiName("java:/jboss/datasources/" + TEST_DATASOURCE_NAME)
            .driverName("h2")
            .usernameAndPassword("creaper2", "creaper2")
            .replaceExisting()
            .build());
    assertTrue("The datasource should be created", ops.exists(TEST_DATASOURCE_ADDRESS));
    assertEquals(
        "The datasource should be replaced with the new one with different username",
        "creaper2",
        ops.readAttribute(TEST_DATASOURCE_ADDRESS, "user-name").stringValue());
  }
コード例 #2
0
  @Test
  public void updateAcceptorSocketBinding() throws IOException, CommandFailedException {
    cliClient.executeCommand(command);
    page.navigateToMessaging();
    page.selectView("Connections");
    page.selectInTable(NAME, 0);
    page.edit();

    String socketBindingName = "RemoteAcceptorSB" + RandomStringUtils.randomAlphanumeric(5);

    try (OnlineManagementClient client = ManagementClientProvider.createOnlineManagementClient()) {
      int port = AvailablePortFinder.getNextAvailable(1024);
      log.info("Obtained port for socket binding '" + socketBindingName + "' is " + port);
      client.apply(new AddSocketBinding.Builder(socketBindingName).port(port).build());
    }

    ConfigFragment editPanelFragment = page.getConfigFragment();

    editPanelFragment.getEditor().text("socketBinding", socketBindingName);
    boolean finished = editPanelFragment.save();

    assertTrue("Config should be saved and closed.", finished);
    verifier.verifyAttribute(address, "socket-binding", socketBindingName, 500);

    cliClient.executeCommand(remove);
  }
コード例 #3
0
  @Test(expected = CommandFailedException.class)
  public void existing() throws Exception {
    AddSecurityRealm addSecurityRealm =
        new AddSecurityRealm.Builder(TEST_SECURITY_REALM_NAME).build();
    AddSecurityRealm addSecurityRealm2 =
        new AddSecurityRealm.Builder(TEST_SECURITY_REALM_NAME).mapGroupsToRoles(true).build();

    client.apply(addSecurityRealm);
    client.apply(addSecurityRealm2);

    fail(
        "Security realm creaperSecRealm already exists in configuration, exception should be thrown");
  }
コード例 #4
0
  private void waitUntilServerIsRunning(boolean reconnect)
      throws IOException, InterruptedException, TimeoutException {

    Thread.sleep(500); // this value is taken from implementation of CLI "reload"

    if (reconnect) {
      client.reconnect(timeoutInSeconds);
    }

    long endTime = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(timeoutInSeconds);
    while (System.currentTimeMillis() < endTime) {
      try {
        if (isServerRunning()) {
          break;
        }
      } catch (Throwable ignored) {
        // server is probably down, will retry
      }

      Thread.sleep(200); // this value is completely arbitrary
    }

    boolean running = false;
    try {
      running = isServerRunning();
    } catch (Throwable ignored) {
      // server probably down
    }
    if (!running) {
      throw new TimeoutException("Waiting for server timed out");
    }
  }
コード例 #5
0
ファイル: Administration.java プロジェクト: istraka/creaper
 public Administration(OnlineManagementClient client, int timeoutInSeconds) {
   if (client.options().isDomain) {
     this.ops = new DomainAdministrationOperations(client, timeoutInSeconds);
   } else {
     this.ops = new StandaloneAdministrationOperations(client, timeoutInSeconds);
   }
 }
コード例 #6
0
 @Test(expected = IllegalArgumentException.class)
 public void addDataSource_commandFailed_usernameAndSecurityDomainDefined() throws Exception {
   AddDataSource addDataSource =
       new AddDataSource.Builder(TEST_DATASOURCE_NAME)
           .jndiName("java:/jboss/datasources/" + TEST_DATASOURCE_NAME)
           .driverName("h2")
           .build();
   client.apply(addDataSource);
 }
コード例 #7
0
  @Test
  public void addSimple() throws Exception {
    AddSecurityRealm addSecurityRealm =
        new AddSecurityRealm.Builder(TEST_SECURITY_REALM_NAME).build();

    assertFalse("The security realm should not exist", ops.exists(TEST_SECURITY_REALM_ADDRESS));
    client.apply(addSecurityRealm);
    assertTrue("The security realm should be created", ops.exists(TEST_SECURITY_REALM_ADDRESS));
  }
コード例 #8
0
 @After
 public void cleanup()
     throws IOException, CliException, OperationException, TimeoutException, InterruptedException {
   try {
     ops.removeIfExists(TEST_DATASOURCE_ADDRESS);
     administration.reloadIfRequired();
   } finally {
     client.close();
   }
 }
コード例 #9
0
 @Test(expected = CommandFailedException.class)
 public void addDataSource_commandFails() throws Exception {
   AddDataSource addDataSource =
       new AddDataSource.Builder(TEST_DATASOURCE_NAME)
           .jndiName("invalid-jndi-name")
           .driverName("h2")
           .connectionUrl("invalid-url")
           .build();
   client.apply(addDataSource);
 }
コード例 #10
0
 @Test(expected = IllegalArgumentException.class)
 public void addDataSource_commandFailed_urlNotDefined() throws Exception {
   AddDataSource addDataSource =
       new AddDataSource.Builder(TEST_DATASOURCE_NAME)
           .jndiName("java:/jboss/datasources/" + TEST_DATASOURCE_NAME)
           .driverName("h2")
           .maxPoolSize(1)
           .usernameAndPassword("creaper", "creaper")
           .securityDomain("other")
           .build();
   client.apply(addDataSource);
 }
コード例 #11
0
  @Test
  public void overrideExisting() throws Exception {
    AddSecurityRealm addSecurityRealm =
        new AddSecurityRealm.Builder(TEST_SECURITY_REALM_NAME).build();
    AddSecurityRealm addSecurityRealm2 =
        new AddSecurityRealm.Builder(TEST_SECURITY_REALM_NAME)
            .mapGroupsToRoles(true)
            .replaceExisting()
            .build();

    client.apply(addSecurityRealm);
    assertTrue("The security realm should be created", ops.exists(TEST_SECURITY_REALM_ADDRESS));
    client.apply(addSecurityRealm2);
    assertTrue("The security realm should be created", ops.exists(TEST_SECURITY_REALM_ADDRESS));

    ModelNodeResult readAttribute =
        ops.readAttribute(TEST_SECURITY_REALM_ADDRESS, "map-groups-to-roles");
    readAttribute.assertSuccess("Read operation for map-groups-to-roles failed");
    Assert.assertEquals(
        "Read operation for map-groups-to-roles return wrong value",
        "true",
        readAttribute.stringValue());
  }
コード例 #12
0
  @Test
  public void addDataSource_commandSuccessful() throws Exception {
    AddDataSource addDataSource =
        new AddDataSource.Builder(TEST_DATASOURCE_NAME)
            .connectionUrl(VALID_DS_URL)
            .jndiName("java:/jboss/datasources/" + TEST_DATASOURCE_NAME)
            .driverName("h2")
            .connectable(false)
            .jta(false)
            .usernameAndPassword("creaper", "creaper")
            .useJavaContext(true)
            .maxPoolSize(666)
            .minPoolSize(0)
            .statisticsEnabled(false)
            .build();
    client.apply(addDataSource);

    assertTrue("The data source should be created", ops.exists(TEST_DATASOURCE_ADDRESS));
  }
コード例 #13
0
 @Test
 public void addDataSourceAndEnable_commandFailed_incorrectPoolSize() throws Exception {
   try {
     AddDataSource addDataSource =
         new AddDataSource.Builder(TEST_DATASOURCE_NAME)
             .connectionUrl(VALID_DS_URL)
             .jndiName("java:/jboss/datasources/" + TEST_DATASOURCE_NAME)
             .driverName("h2")
             .maxPoolSize(-1) // improper value which causes enable to fail
             .enableAfterCreate()
             .build();
     client.apply(addDataSource);
     fail("Command should fail");
   } catch (IllegalArgumentException expected) {
     assertFalse(
         "The datasource shouldn't be created as the command should be composite and enable should fail",
         ops.exists(TEST_DATASOURCE_ADDRESS));
   }
 }
コード例 #14
0
  @Test
  public void addDataSourceAndEnable_commandSuccessful() throws Exception {
    AddDataSource addDataSource =
        new AddDataSource.Builder(TEST_DATASOURCE_NAME)
            .connectionUrl(VALID_DS_URL)
            .jndiName("java:/jboss/datasources/" + TEST_DATASOURCE_NAME)
            .driverName("h2")
            .enableAfterCreate()
            .connectable(false)
            .jta(false)
            .usernameAndPassword("creaper", "creaper")
            .useJavaContext(true)
            .build();
    client.apply(addDataSource);

    assertTrue("The data source should be created", ops.exists(TEST_DATASOURCE_ADDRESS));
    assertTrue(
        "The data source should be enabled",
        ops.readAttribute(TEST_DATASOURCE_ADDRESS, "enabled").booleanValue());
  }
コード例 #15
0
  @Test
  public void addDataSource_commandSuccessful_fullLoad() throws Exception {
    AddDataSource addDataSource =
        new AddDataSource.Builder(TEST_DATASOURCE_NAME)
            .connectionUrl(VALID_DS_URL)
            .jndiName("java:/jboss/datasources/" + TEST_DATASOURCE_NAME)
            .driverName("h2")
            .usernameAndPassword("creaper", "creaper")
            .allocationRetry(3)
            .allocationRetryWaitMillis(1000)
            .allowMultipleUsers(true)
            .backgroundValidation(true)
            .backgroundValidationMillis(1000)
            .blockingTimeoutWaitMillis(1000)
            .checkValidConnectionSql("SELECT 1")
            .connectable(true)
            .addConnectionProperty("other-user-name", "right-its-other-username")
            .datasourceClass("org.h2.jdbcx.JdbcDataSource")
            .driverClass("org.h2.Driver")
            .exceptionSorterClass(
                "org.jboss.jca.adapters.jdbc.extensions.novendor.NullExceptionSorter")
            .addExceptionSorterProperty("exception-sorter-prop", "ok")
            .idleTimeoutMinutes(10)
            .jta(true)
            .managedConnectionPool(
                "org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreConcurrentLinkedDequeManagedConnectionPool")
            .maxPoolSize(1)
            .minPoolSize(1)
            .newConnectionSql("SELECT 1")
            .flushStrategy(PoolFlushStrategy.ENTIRE_POOL)
            .prefill(true)
            .preparedStatementsCacheSize(3)
            .queryTimeout(20)
            // .reauthPluginClass() - no null reauth plugin exists
            // .securityDomain("other") - can't be used as interferes with usage of username
            .setTxQueryTimeout(true)
            .sharePreparedStatements(true)
            .spy(true)
            .staleConnectionCheckerClass(
                "org.jboss.jca.adapters.jdbc.extensions.novendor.NullStaleConnectionChecker")
            .addStaleConnectionCheckerProperty("stale-checker-prop", "ok")
            .statisticsEnabled(true)
            .trackPreparedStatements(TrackStatementType.TRUE)
            .transactionIsolation(TransactionIsolation.TRANSACTION_REPEATABLE_READ)
            .urlDelimiter(";")
            // .urlSelectorStrategyClass() - can't find any implementation of SPI
            .useCcm(true)
            .useFastFailAllocation(false)
            .useJavaContext(true)
            .useStrictMinPoolSize(true)
            .useTryLock(60)
            .validateOnMatch(true)
            .validConnectionCheckerClass(
                "org.jboss.jca.adapters.jdbc.extensions.novendor.NullValidConnectionChecker")
            .addValidConnectionCheckerProperty("valid-checker-prop", "ok")
            .build();

    client.apply(addDataSource);

    assertTrue("The datasource should be created", ops.exists(TEST_DATASOURCE_ADDRESS));
  }