/** * Performs a simple count validation on the specified search index. * * @param indexName the name of the index * @param documentType the document type * @param expectedIndexSize the expected index size * * @return true if index size matches the expected size, false otherwise */ protected boolean validateSearchIndexSize(String indexName, String documentType, int expectedIndexSize) { final long indexSize = indexFunctionsDao.getNumberOfTypesInIndex(indexName, documentType); boolean result = true; if (indexSize != expectedIndexSize) { LOGGER.error("Index validation failed, expected index size {}, does not equal actual index size {}.", expectedIndexSize, indexSize); result = false; } return result; } }
/** * Performs a simple count validation on the specified search index. * * @param indexName the name of the index * @param documentType the document type * @param expectedIndexSize the expected index size * * @return true if index size matches the expected size, false otherwise */ protected boolean validateSearchIndexSize(String indexName, String documentType, int expectedIndexSize) { final long indexSize = indexFunctionsDao.getNumberOfTypesInIndex(indexName, documentType); boolean result = true; if (indexSize != expectedIndexSize) { LOGGER.error("Index validation failed, expected index size {}, does not equal actual index size {}.", expectedIndexSize, indexSize); result = false; } return result; } }
@Override public boolean indexSizeCheckValidationTags(String indexName) { final String documentType = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); // Simple count validation, index size should equal entity list size final long indexSize = indexFunctionsDao.getNumberOfTypesInIndex(indexName, documentType); final long tagDatabaseTableSize = tagDao.getCountOfAllTags(); if (tagDatabaseTableSize != indexSize) { LOGGER.error("Index validation failed, tag database table size {}, does not equal index size {}.", tagDatabaseTableSize, indexSize); } return tagDatabaseTableSize == indexSize; }
@Override public boolean indexSizeCheckValidationBusinessObjectDefinitions(String indexName) { final String documentType = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); // Simple count validation, index size should equal entity list size final long indexSize = indexFunctionsDao.getNumberOfTypesInIndex(indexName, documentType); final long businessObjectDefinitionDatabaseTableSize = businessObjectDefinitionDao.getCountOfAllBusinessObjectDefinitions(); if (businessObjectDefinitionDatabaseTableSize != indexSize) { LOGGER.error("Index validation failed, business object definition database table size {}, does not equal index size {}.", businessObjectDefinitionDatabaseTableSize, indexSize); } return businessObjectDefinitionDatabaseTableSize == indexSize; }
@Override public boolean indexSizeCheckValidationBusinessObjectDefinitions(String indexName) { final String documentType = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); // Simple count validation, index size should equal entity list size final long indexSize = indexFunctionsDao.getNumberOfTypesInIndex(indexName, documentType); final long businessObjectDefinitionDatabaseTableSize = businessObjectDefinitionDao.getCountOfAllBusinessObjectDefinitions(); if (businessObjectDefinitionDatabaseTableSize != indexSize) { LOGGER.error("Index validation failed, business object definition database table size {}, does not equal index size {}.", businessObjectDefinitionDatabaseTableSize, indexSize); } return businessObjectDefinitionDatabaseTableSize == indexSize; }
@Override public boolean indexSizeCheckValidationTags(String indexName) { final String documentType = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); // Simple count validation, index size should equal entity list size final long indexSize = indexFunctionsDao.getNumberOfTypesInIndex(indexName, documentType); final long tagDatabaseTableSize = tagDao.getCountOfAllTags(); if (tagDatabaseTableSize != indexSize) { LOGGER.error("Index validation failed, tag database table size {}, does not equal index size {}.", tagDatabaseTableSize, indexSize); } return tagDatabaseTableSize == indexSize; }
@Test public void testValidateSearchIndexSizeValidationFails() { // Mock the external calls. Please note that we mock index size not to be equal to the business object definition entity list size. when(indexFunctionsDao.getNumberOfTypesInIndex(SEARCH_INDEX_NAME, SEARCH_INDEX_DOCUMENT_TYPE)).thenReturn(1L); // Index all business object definitions defined in the system. boolean response = searchIndexHelperServiceImpl.validateSearchIndexSize(SEARCH_INDEX_NAME, SEARCH_INDEX_DOCUMENT_TYPE, 2); // Verify the external calls. verify(indexFunctionsDao).getNumberOfTypesInIndex(SEARCH_INDEX_NAME, SEARCH_INDEX_DOCUMENT_TYPE); verifyNoMoreInteractions(businessObjectDefinitionDao, businessObjectDefinitionHelper, indexFunctionsDao, searchIndexDaoHelper); // Validate the results. assertFalse(response); }
@Test public void testValidateSearchIndexSizeValidationPasses() { // Mock the external calls. Please note that we mock index size to be equal to the business object definition entity list size. when(indexFunctionsDao.getNumberOfTypesInIndex(SEARCH_INDEX_NAME, SEARCH_INDEX_DOCUMENT_TYPE)).thenReturn(2L); // Index all business object definitions defined in the system. boolean response = searchIndexHelperServiceImpl.validateSearchIndexSize(SEARCH_INDEX_NAME, SEARCH_INDEX_DOCUMENT_TYPE, 2); // Verify the external calls. verify(indexFunctionsDao).getNumberOfTypesInIndex(SEARCH_INDEX_NAME, SEARCH_INDEX_DOCUMENT_TYPE); verifyNoMoreInteractions(businessObjectDefinitionDao, businessObjectDefinitionHelper, indexFunctionsDao, searchIndexDaoHelper); // Validate the results. assertTrue(response); } }
@Test public void testIndexSizeCheckValidationTags() throws Exception { // Mock the call to external methods when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn("DOCUMENT_TYPE"); when(indexFunctionsDao.getNumberOfTypesInIndex(any(), any())).thenReturn(100L); when(tagDao.getCountOfAllTags()).thenReturn(100L); // Call the method under test boolean isIndexSizeValid = tagService.indexSizeCheckValidationTags(SEARCH_INDEX_TYPE_TAG); assertThat("Tag service index size validation is false when it should have been true.", isIndexSizeValid, is(true)); // Verify the calls to external methods verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); verify(indexFunctionsDao).getNumberOfTypesInIndex(any(), any()); verify(tagDao).getCountOfAllTags(); verifyNoMoreInteractions(tagDao, indexFunctionsDao, configurationHelper); }
@Test public void testIndexSizeCheckValidationTagsFalse() throws Exception { // Mock the call to external methods when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn("DOCUMENT_TYPE"); when(indexFunctionsDao.getNumberOfTypesInIndex(any(), any())).thenReturn(100L); when(tagDao.getCountOfAllTags()).thenReturn(200L); // Call the method under test boolean isIndexSizeValid = tagService.indexSizeCheckValidationTags(SEARCH_INDEX_TYPE_TAG); assertThat("Tag service index size validation is true when it should have been false.", isIndexSizeValid, is(false)); // Verify the calls to external methods verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); verify(indexFunctionsDao).getNumberOfTypesInIndex(any(), any()); verify(tagDao).getCountOfAllTags(); verifyNoMoreInteractions(tagDao, configurationHelper); }
@Test public void testIndexSizeCheckValidationBusinessObjectDefinitions() { // Mock the call to external methods when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn(SEARCH_INDEX_DOCUMENT_TYPE); when(indexFunctionsDao.getNumberOfTypesInIndex(any(), any())).thenReturn(100L); when(businessObjectDefinitionDao.getCountOfAllBusinessObjectDefinitions()).thenReturn(100L); // Call the method under test boolean isIndexSizeValid = businessObjectDefinitionService.indexSizeCheckValidationBusinessObjectDefinitions(SEARCH_INDEX_NAME); assertThat("Business object definition service index size validation is false when it should have been true.", isIndexSizeValid, is(true)); // Verify the calls to external methods verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); verify(indexFunctionsDao).getNumberOfTypesInIndex(any(), any()); verify(businessObjectDefinitionDao).getCountOfAllBusinessObjectDefinitions(); verifyNoMoreInteractionsHelper(); }
@Test public void testIndexSizeCheckValidationBusinessObjectDefinitionsFalse() { // Mock the call to external methods when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn(SEARCH_INDEX_DOCUMENT_TYPE); when(indexFunctionsDao.getNumberOfTypesInIndex(any(), any())).thenReturn(100L); when(businessObjectDefinitionDao.getCountOfAllBusinessObjectDefinitions()).thenReturn(200L); // Call the method under test boolean isIndexSizeValid = businessObjectDefinitionService.indexSizeCheckValidationBusinessObjectDefinitions(SEARCH_INDEX_NAME); assertThat("Business object definition service index size validation is true when it should have been false.", isIndexSizeValid, is(false)); // Verify the calls to external methods verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); verify(indexFunctionsDao).getNumberOfTypesInIndex(any(), any()); verify(businessObjectDefinitionDao).getCountOfAllBusinessObjectDefinitions(); verifyNoMoreInteractionsHelper(); }
doNothing().when(indexFunctionsDao).createIndexDocument(any(), any(), any(), any()); when(indexFunctionsDao.getNumberOfTypesInIndex(SEARCH_INDEX_NAME, SEARCH_INDEX_DOCUMENT_TYPE)).thenReturn(2L); verify(indexFunctionsDao).getNumberOfTypesInIndex(SEARCH_INDEX_NAME, SEARCH_INDEX_DOCUMENT_TYPE); verify(searchIndexDaoHelper).updateSearchIndexStatus(searchIndexKey, SearchIndexStatusEntity.SearchIndexStatuses.READY.name()); verifyNoMoreInteractions(businessObjectDefinitionDao, businessObjectDefinitionHelper, searchIndexDaoHelper, tagDao, tagHelper);
when(businessObjectDefinitionDao.getAllBusinessObjectDefinitions(chunkSize, chunkSize)).thenReturn(new ArrayList<>()); when(indexFunctionsDao.getNumberOfTypesInIndex(any(), any())).thenReturn(2L); .executeFunctionForBusinessObjectDefinitionEntities(eq(SEARCH_INDEX_NAME), eq(SEARCH_INDEX_DOCUMENT_TYPE), eq(businessObjectDefinitionEntities), any()); verify(indexFunctionsDao).getNumberOfTypesInIndex(any(), any()); verify(searchIndexDaoHelper).updateSearchIndexStatus(searchIndexKey, SearchIndexStatusEntity.SearchIndexStatuses.READY.name()); verifyNoMoreInteractions(businessObjectDefinitionDao, businessObjectDefinitionHelper, searchIndexDaoHelper, tagDao, tagHelper);
when(mockedDocsStats.getDeleted()).thenReturn(SEARCH_INDEX_STATISTICS_NUMBER_OF_DELETED_DOCUMENTS); when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn("doc"); when(indexFunctionsDao.getNumberOfTypesInIndex(any(), any())).thenReturn(0l); verify(indexFunctionsDao).getIndexStats(SEARCH_INDEX_NAME); verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); verify(indexFunctionsDao).getNumberOfTypesInIndex(any(), any());
long indexCount = indexFunctionsDao.getNumberOfTypesInIndex(searchIndexKey.getSearchIndexName(), documentType);
long indexCount = indexFunctionsDao.getNumberOfTypesInIndex(searchIndexKey.getSearchIndexName(), documentType);