@PostConstruct
  public void init() throws Exception {
    log = Logger.getLogger(getClass().getName());
    Properties settings = SearchUtils.loadProperties("/search_client_settings.properties");

    if (ClientType.EMBEDDED.equals(appConfigurationService.getAppConfiguration().getClientType())) {
      node = createEmbeddedNode("search", settings);
      client = node.client();
      return;
    } else {
      Properties transportAddresses =
          SearchUtils.loadProperties("/search_client_connections.properties");
      client = createTransportClient(transportAddresses, settings);
    }

    checkHealthOfCluster(client);
  }
Beispiel #2
0
 /**
  * Convert request parameter to enum item.
  *
  * @param requestVal value from request to parse
  * @return enum item for given request value, null if it is empty
  * @throws IllegalArgumentException if request value is invalid
  */
 public static SortByValue parseRequestParameterValue(String requestVal)
     throws IllegalArgumentException {
   requestVal = SearchUtils.trimToNull(requestVal);
   if (requestVal == null) return null;
   for (SortByValue n : SortByValue.values()) {
     if (n.value.equals(requestVal)) return n;
   }
   throw new IllegalArgumentException(QuerySettings.SORT_BY_KEY);
 }
  @Test
  public void store_get_delete() throws Exception {
    JdbcContentPersistenceService tested = getTested();

    // case - get from noexisting table
    Assert.assertNull(tested.get("a-1", "tt"));

    String sysContentType = "testtype_1";
    Map<String, Object> content = null;
    // case - store into nonexisting table, nonexisting id
    tested.store("aaa-1", sysContentType, content);

    assertRowCount(tested, sysContentType, 1);
    Assert.assertNull(tested.get("aaa-1", sysContentType));

    // case - get nonexisting id from existing table
    Assert.assertNull(tested.get("a-1", sysContentType));

    // case - test persistence after commit
    assertRowCount(tested, sysContentType, 1);
    Assert.assertNull(tested.get("aaa-1", sysContentType));

    // case - store into existing table, nonexisting id
    content = new HashMap<String, Object>();
    content.put("testkey", "testvalue");
    tested.store("aaa-2", sysContentType, content);
    assertRowCount(tested, sysContentType, 2);
    Assert.assertNull(tested.get("aaa-1", sysContentType));
    TestUtils.assertJsonContent(
        "{\"testkey\" : \"testvalue\"}", tested.get("aaa-2", sysContentType));

    // case - store into existing table, existing id so update, sys_updated is Date instance
    content.put(ContentObjectFields.SYS_UPDATED, new Date(65463749865l));
    tested.store("aaa-1", sysContentType, content);
    assertRowCount(tested, sysContentType, 2);
    TestUtils.assertJsonContent(
        "{\"testkey\" : \"testvalue\", \"sys_updated\":\"1972-01-28T16:22:29.865Z\"}",
        tested.get("aaa-1", sysContentType));
    assertTableContent(
        tested,
        sysContentType,
        "aaa-1",
        SearchUtils.getISODateFormat().parse("1972-01-28T16:22:29.865+0000"));
    // case - store into existing table, existing id so update, sys_updated is ISO String instance
    content.put(ContentObjectFields.SYS_UPDATED, "1973-01-28T17:22:29.865+0100");
    tested.store("aaa-2", sysContentType, content);
    assertRowCount(tested, sysContentType, 2);
    TestUtils.assertJsonContent(
        "{\"testkey\" : \"testvalue\", \"sys_updated\":\"1973-01-28T17:22:29.865+0100\"}",
        tested.get("aaa-2", sysContentType));
    assertTableContent(
        tested,
        sysContentType,
        "aaa-2",
        SearchUtils.getISODateFormat().parse("1973-01-28T17:22:29.865+0100"));

    // case - store into existing table, existing id so update, sys_updated is invalid String
    // instance but no
    // exception and table is correctly filled
    content.put(ContentObjectFields.SYS_UPDATED, "sdfasdf");
    tested.store("aaa-2", sysContentType, content);
    assertRowCount(tested, sysContentType, 2);
    TestUtils.assertJsonContent(
        "{\"testkey\" : \"testvalue\", \"sys_updated\":\"sdfasdf\"}",
        tested.get("aaa-2", sysContentType));
    assertTableContent(tested, sysContentType, "aaa-2", null);

    // case - delete from nonexisting table
    tested.delete("aaa", "jj");

    // case - delete from existing table, nonexisting id
    tested.delete("a-1", sysContentType);
    assertRowCount(tested, sysContentType, 2);

    // case - delete existing id
    tested.delete("aaa-1", sysContentType);
    assertRowCount(tested, sysContentType, 1);
    Assert.assertNull(tested.get("aaa-1", sysContentType));
    Assert.assertNotNull(tested.get("aaa-2", sysContentType));
  }