@Override public List<String> getIndices() { return indexes.keySet().stream().map(kCluster -> kCluster.getClusterId()).collect(Collectors.toList()); } }
@Override public void delete(KCluster cluster) { this.batchLocks.remove(cluster); this.provider.delete(cluster.getClusterId()); }
@Override public void delete(KCluster cluster) { this.batchLocks.remove(cluster); this.provider.delete(cluster.getClusterId()); }
@Override public boolean isFreshIndex(KCluster cluster) { return this.getIndexSize(cluster.getClusterId()) == 0; }
@Override public boolean isFreshIndex(KCluster cluster) { return this.getIndexSize(cluster.getClusterId()) == 0; }
@Override public void startBatch(KCluster cluster) { prepareBatch(cluster); Map<KCluster, List<IndexEvent>> batchSet = batchSets.get(); if (batchSet.containsKey(cluster)) { throw new IllegalStateException(String.format("Cannot start a batch for cluster [id=%s] when there is already a batch started on this thread [%s]", cluster.getClusterId(), Thread.currentThread().getName())); } else { batchSet.put(cluster, new ArrayList<>()); } }
@Override public boolean isFreshIndex(KCluster cluster) { return this.getIndexSize(cluster.getClusterId()) == 0; }
@Override public void startBatch(KCluster cluster) { prepareBatch(cluster); Map<KCluster, List<IndexEvent>> batchSet = batchSets.get(); if (batchSet.containsKey(cluster)) { throw new IllegalStateException(String.format("Cannot start a batch for cluster [id=%s] when there is already a batch started on this thread [%s]", cluster.getClusterId(), Thread.currentThread().getName())); } else { batchSet.put(cluster, new ArrayList<>()); } }
@Override public boolean isFreshIndex(KCluster cluster) { return this.getIndexSize(cluster.getClusterId()) == 0; }
@Before public void setup() { cluster = new KClusterImpl("test-cluster"); kObject = new KObjectImpl("1", "java", cluster.getClusterId(), "segment", "key", Collections.emptyList(), true); kObjectKey = new KObjectKeyImpl("key", "2", "java", cluster.getClusterId(), "segment"); indexEngine = new MetadataIndexEngine(provider, metaModelStore, () -> lock); }
@Before public void setup() { cluster = new KClusterImpl("test-cluster"); kObject = new KObjectImpl("1", "java", cluster.getClusterId(), "segment", "key", Collections.emptyList(), true); kObjectKey = new KObjectKeyImpl("key", "2", "java", cluster.getClusterId(), "segment"); indexEngine = new MetadataIndexEngine(provider, metaModelStore, () -> lock); }
@Test public void testIndexingFullText() throws IOException, InterruptedException { //Add test files loadProperties("file1.properties", basePath); loadProperties("file2.properties", basePath); Thread.sleep(5000); //wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath).getClusterId()); searchFor(index, new WildcardQuery(new Term(FULL_TEXT_FIELD, "*file*")), 2); }
@Test public void testIndexingAddedResources() throws IOException, InterruptedException { //Add test files loadProperties("file1.properties", basePath); loadProperties("file2.properties", basePath); loadProperties("file3.properties", basePath); loadProperties("file4.properties", basePath); Thread.sleep(5000); //wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index List<String> indices = Arrays.asList(KObjectUtil.toKCluster(basePath).getClusterId()); searchFor(indices, (Query) new TermQuery(new Term("title", "lucene")), 2); }
@Test public void testIndexingDeletedResources() throws IOException, InterruptedException { //Add test files loadProperties("file1.properties", basePath); loadProperties("file2.properties", basePath); loadProperties("file3.properties", basePath); loadProperties("file4.properties", basePath); Thread.sleep(5000); //wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath).getClusterId()); searchFor(index, new TermQuery(new Term("title", "lucene")), 2); //Delete one of the files returned by the previous search, removing the "lucene" title ioService().delete(basePath.resolve("file1.properties")); Thread.sleep(5000); //wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index searchFor(index, new TermQuery(new Term("title", "lucene")), 1); }
@Test public void testIndexDecisionTableXLSAttributeName() throws IOException, InterruptedException { //Add test files final Path path1 = loadXLSFile(basePath, "dtable1.xls"); Thread.sleep(5000); //wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath).getClusterId()); { final Query query = new SingleTermQueryBuilder(new ValueSharedPartIndexTerm("*", PartType.RULEFLOW_GROUP, TermSearchType.WILDCARD)) .build(); searchFor(index, query, 1, path1); } }
@Test public void testIndexDecisionTableXLSAttributeNameAndValue() throws IOException, InterruptedException { //Add test files final Path path1 = loadXLSFile(basePath, "dtable1.xls"); final Path path2 = loadXLSFile(basePath, "dtable2.xls"); Thread.sleep(5000); //wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath).getClusterId()); //This simply checks whether there is a Rule Attribute "ruleflow-group" with a Rule Attribute Value "myRuleflowGroup" { final BooleanQuery.Builder query = new BooleanQuery.Builder(); ValueIndexTerm valTerm = new ValueSharedPartIndexTerm("myruleflowgroup", PartType.RULEFLOW_GROUP); query.add(new TermQuery(new Term(valTerm.getTerm(), valTerm.getValue())), BooleanClause.Occur.MUST); searchFor(index, query.build(), 1, path1); } }
@Test public void testIndexDecisionTableXLSAttributeNameAndValue() throws IOException, InterruptedException { //Add test files final Path path1 = loadXLSFile(basePath, "dtable1.xls"); final Path path2 = loadXLSFile(basePath, "dtable2.xls"); Thread.sleep(5000); //wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath).getClusterId()); //This simply checks whether there is a Rule Attribute "ruleflow-group" with a Rule Attribute Value "myRuleflowGroup" { final BooleanQuery.Builder query = new BooleanQuery.Builder(); ValueIndexTerm valTerm = new ValueSharedPartIndexTerm("myruleflowgroup", PartType.RULEFLOW_GROUP); query.add(new TermQuery(new Term(valTerm.getTerm(), valTerm.getValue())), BooleanClause.Occur.MUST); searchFor(index, query.build(), 1, path1); } }
@Test public void testIndexDecisionTableXLSAttributeName() throws IOException, InterruptedException { //Add test files final Path path1 = loadXLSFile(basePath, "dtable1.xls"); Thread.sleep(5000); //wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath).getClusterId()); { final Query query = new SingleTermQueryBuilder(new ValueSharedPartIndexTerm("*", PartType.RULEFLOW_GROUP, TermSearchType.WILDCARD)) .build(); searchFor(index, query, 1, path1); } }
@Test public void testIndexedGitInternalDotFile() throws IOException, InterruptedException { setupCountDown(1); final Path path1 = getBasePath(this.getClass().getSimpleName()).resolve(".gitkeep"); ioService().write(path1, "ooooo!", Collections.<OpenOption>emptySet(), getFileAttributes()); final Path path2 = getBasePath(this.getClass().getSimpleName()).resolve("afile"); ioService().write(path2, "ooooo!", Collections.<OpenOption>emptySet(), getFileAttributes()); waitForCountDown(5000); final String index = toKCluster(path1).getClusterId(); TermQuery query = new TermQuery(new Term("name", "value")); List<KObject> hits = config.getIndexProvider().findByQuery(Arrays.asList(index), query, 10); assertEquals(1, hits.size()); assertEquals(hits.get(0).getKey(), path2.toUri().toString()); }
@Test public void testIndexDecisionTableXLSMultipleTypes() throws IOException, InterruptedException { //Add test files final Path path = loadXLSFile(basePath, "xlsxrule.xlsx"); Thread.sleep(5000); //wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath).getClusterId()); { final Query query = new SingleTermQueryBuilder( new ValueResourceIndexTerm("*", ResourceType.RULE, ValueIndexTerm.TermSearchType.WILDCARD) ) .build(); // Rule name found from xlsxrule searchFor(index, query, 1, path); } }