org.elasticsearch.ResourceNotFoundException Java Examples

The following examples show how to use org.elasticsearch.ResourceNotFoundException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClientFacadeTest.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
void testIndexThrowsResourceNotFoundException() {
  Index index = Index.create("index");

  when(document.getContent()).thenReturn(xContentBuilder);
  when(document.getId()).thenReturn("id");

  when(client.prepareIndex()).thenReturn(indexRequestBuilder);
  when(indexRequestBuilder.setIndex("index")).thenReturn(indexRequestBuilder);
  when(indexRequestBuilder.setType(any())).thenReturn(indexRequestBuilder);
  when(indexRequestBuilder.setId("id")).thenReturn(indexRequestBuilder);
  when(indexRequestBuilder.setSource(xContentBuilder)).thenReturn(indexRequestBuilder);

  when(indexRequestBuilder.get()).thenThrow(new ResourceNotFoundException("exception"));

  Exception exception =
      assertThrows(UnknownIndexException.class, () -> clientFacade.index(index, document));
  assertThat(exception.getMessage()).containsPattern("Index 'index' not found\\.");
}
 
Example #2
Source File: ClientFacadeTest.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
void testDeleteResourceNotFound() {
  Index index = Index.create("index");

  when(document.getId()).thenReturn("id");

  when(client.prepareDelete()).thenReturn(deleteRequestBuilder);
  when(deleteRequestBuilder.setIndex("index")).thenReturn(deleteRequestBuilder);
  when(deleteRequestBuilder.setType(any())).thenReturn(deleteRequestBuilder);
  when(deleteRequestBuilder.setId("id")).thenReturn(deleteRequestBuilder);

  when(deleteRequestBuilder.get()).thenThrow(new ResourceNotFoundException("exception"));

  Exception exception =
      assertThrows(UnknownIndexException.class, () -> clientFacade.deleteById(index, document));
  assertThat(exception.getMessage()).containsPattern("Index 'index' not found\\.");
}
 
Example #3
Source File: SqlFeatures.java    From crate with Apache License 2.0 6 votes vote down vote up
public static Iterable<SqlFeatureContext> loadFeatures() throws IOException {
    try (InputStream sqlFeatures = SqlFeatures.class.getResourceAsStream("/sql_features.tsv")) {
        if (sqlFeatures == null) {
            throw new ResourceNotFoundException("sql_features.tsv file not found");
        }
        ArrayList<SqlFeatureContext> featuresList = new ArrayList<>();
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(sqlFeatures, StandardCharsets.UTF_8))) {
            String next;
            while ((next = reader.readLine()) != null) {
                List<String> parts = List.of(next.split("\t", NUM_COLS));
                var ctx = new SqlFeatureContext(parts.get(0),
                    parts.get(1),
                    parts.get(2),
                    parts.get(3),
                    parts.get(4).equals("YES"),
                    parts.get(5).isEmpty() ? null : parts.get(5),
                    parts.get(6).isEmpty() ? null : parts.get(6));
                featuresList.add(ctx);
            }
        }
        return featuresList;
    }
}
 
Example #4
Source File: TransportSchemaUpdateAction.java    From crate with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
static ClusterState updateTemplate(NamedXContentRegistry xContentRegistry,
                                   ClusterState currentState,
                                   String templateName,
                                   Map<String, Object> newMapping) throws Exception {
    IndexTemplateMetaData template = currentState.metaData().templates().get(templateName);
    if (template == null) {
        throw new ResourceNotFoundException("Template \"" + templateName + "\" for partitioned table is missing");
    }

    IndexTemplateMetaData.Builder templateBuilder = new IndexTemplateMetaData.Builder(template);
    for (ObjectObjectCursor<String, CompressedXContent> cursor : template.mappings()) {
        Map<String, Object> source = parseMapping(xContentRegistry, cursor.value.toString());
        mergeIntoSource(source, newMapping);
        try (XContentBuilder xContentBuilder = JsonXContent.contentBuilder()) {
            templateBuilder.putMapping(cursor.key, Strings.toString(xContentBuilder.map(source)));
        }
    }
    MetaData.Builder builder = MetaData.builder(currentState.metaData()).put(templateBuilder);
    return ClusterState.builder(currentState).metaData(builder).build();
}
 
Example #5
Source File: ClientFacadeTest.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
void testRefreshIndicesNotFound() {
  when(indicesAdminClient.prepareRefresh("_all")).thenReturn(refreshRequestBuilder);
  when(refreshRequestBuilder.get()).thenThrow(new ResourceNotFoundException("exception"));

  Exception exception =
      assertThrows(UnknownIndexException.class, () -> clientFacade.refreshIndexes());
  assertThat(exception.getMessage()).containsPattern("One or more indexes '_all' not found\\.");
}
 
Example #6
Source File: ClientFacadeTest.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
void testGetCountThrowsResourceNotFoundException() {
  Index index = Index.create("index");

  when(client.prepareSearch("index")).thenReturn(searchRequestBuilder);
  when(searchRequestBuilder.get()).thenThrow(new ResourceNotFoundException("exception"));

  Exception exception =
      assertThrows(UnknownIndexException.class, () -> clientFacade.getCount(index));
  assertThat(exception.getMessage()).containsPattern("One or more indexes 'index' not found\\.");
}
 
Example #7
Source File: ClientFacadeTest.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
void testSearchIndexNotFound() {
  Index index = Index.create("index");

  when(client.prepareSearch("index")).thenReturn(searchRequestBuilder);
  when(searchRequestBuilder.get()).thenThrow(new ResourceNotFoundException("Exception"));
  when(queryBuilder.toString()).thenReturn("a == b");

  Exception exception =
      assertThrows(
          UnknownIndexException.class,
          () -> clientFacade.search(queryBuilder, 0, 100, ImmutableList.of(index)));
  assertThat(exception.getMessage()).containsPattern("One or more indexes 'index' not found\\.");
}
 
Example #8
Source File: ClientFacadeTest.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
void testAggregateThrowsResourceNotFoundException() {
  Index index = Index.create("index");

  when(client.prepareSearch("index")).thenReturn(searchRequestBuilder);
  when(searchRequestBuilder.get()).thenThrow(new ResourceNotFoundException("Exception"));
  when(queryBuilder.toString()).thenReturn("a == b");

  Exception exception =
      assertThrows(
          UnknownIndexException.class,
          () ->
              clientFacade.aggregate(ImmutableList.of(aggregationBuilder), queryBuilder, index));
  assertThat(exception.getMessage()).containsPattern("One or more indexes 'index' not found\\.");
}