Skip to content

Commit

Permalink
converts test to new executor
Browse files Browse the repository at this point in the history
refs #7155
  • Loading branch information
robfrank committed Mar 2, 2017
1 parent b248bb3 commit 3cd894f
Show file tree
Hide file tree
Showing 18 changed files with 1,632 additions and 18 deletions.
Expand Up @@ -85,6 +85,7 @@ public OIdentifiable next() {
String rId = ret.get(OLuceneIndexEngineAbstract.RID); String rId = ret.get(OLuceneIndexEngineAbstract.RID);
res = new OContextualRecordId(rId); res = new OContextualRecordId(rId);
engine.onRecordAddedToResultSet(queryContext, res, ret, score); engine.onRecordAddedToResultSet(queryContext, res, ret, score);

} catch (IOException e) { } catch (IOException e) {
//TODO handle in a proper way //TODO handle in a proper way
e.printStackTrace(); e.printStackTrace();
Expand Down
Expand Up @@ -14,7 +14,10 @@
import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.IndexableField;
import org.apache.lucene.index.memory.MemoryIndex; import org.apache.lucene.index.memory.MemoryIndex;


import java.util.*; import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;


import static com.orientechnologies.lucene.functions.OLuceneFunctionsUtils.getOrCreateMemoryIndex; import static com.orientechnologies.lucene.functions.OLuceneFunctionsUtils.getOrCreateMemoryIndex;
Expand Down Expand Up @@ -49,7 +52,7 @@ public Object execute(Object iThis,
OElement element = result.toElement(); OElement element = result.toElement();


String className = element.getSchemaType().get().getName(); String className = element.getSchemaType().get().getName();
String[] fieldNames = ((String) params[0]).split(","); List<String> fieldNames = (List<String>) params[0];


OLuceneFullTextIndex index = searchForIndex(className, ctx, fieldNames); OLuceneFullTextIndex index = searchForIndex(className, ctx, fieldNames);


Expand Down Expand Up @@ -96,7 +99,7 @@ public Iterable<OIdentifiable> searchFromTarget(OFromClause target,
OCommandContext ctx, OCommandContext ctx,
OExpression... args) { OExpression... args) {


String[] fieldNames = ((String) args[0].execute((OIdentifiable) null, ctx)).split(","); List<String> fieldNames = (List<String>) args[0].execute((OIdentifiable) null, ctx);


OFromItem item = target.getItem(); OFromItem item = target.getItem();
String className = item.getIdentifier().getStringValue(); String className = item.getIdentifier().getStringValue();
Expand All @@ -123,7 +126,7 @@ public Iterable<OIdentifiable> searchFromTarget(OFromClause target,


} }


private OLuceneFullTextIndex searchForIndex(String className, OCommandContext ctx, String[] fieldNames) { private OLuceneFullTextIndex searchForIndex(String className, OCommandContext ctx, List<String> fieldNames) {
OMetadata dbMetadata = ctx.getDatabase().activateOnCurrentThread().getMetadata(); OMetadata dbMetadata = ctx.getDatabase().activateOnCurrentThread().getMetadata();


List<OLuceneFullTextIndex> indices = dbMetadata List<OLuceneFullTextIndex> indices = dbMetadata
Expand All @@ -132,7 +135,7 @@ private OLuceneFullTextIndex searchForIndex(String className, OCommandContext ct
.stream() .stream()
.filter(idx -> idx instanceof OLuceneFullTextIndex) .filter(idx -> idx instanceof OLuceneFullTextIndex)
.map(idx -> (OLuceneFullTextIndex) idx) .map(idx -> (OLuceneFullTextIndex) idx)
.filter(idx -> intersect(idx.getDefinition().getFields(), Arrays.asList(fieldNames))) .filter(idx -> intersect(idx.getDefinition().getFields(), fieldNames))
.collect(Collectors.toList()); .collect(Collectors.toList());


if (indices.size() > 1) { if (indices.size() > 1) {
Expand Down
Expand Up @@ -19,7 +19,6 @@ public class OLuceneSearchOnFieldsFunctionTest extends BaseLuceneTest {
public void setUp() throws Exception { public void setUp() throws Exception {
InputStream stream = ClassLoader.getSystemResourceAsStream("testLuceneIndex.sql"); InputStream stream = ClassLoader.getSystemResourceAsStream("testLuceneIndex.sql");


// db.command(new OCommandScript("sql", getScriptFromStream(stream))).execute();
db.execute("sql", getScriptFromStream(stream)); db.execute("sql", getScriptFromStream(stream));


db.command("create index Song.title on Song (title) FULLTEXT ENGINE LUCENE "); db.command("create index Song.title on Song (title) FULLTEXT ENGINE LUCENE ");
Expand All @@ -33,7 +32,7 @@ public void setUp() throws Exception {
public void shouldSearchOnSingleField() throws Exception { public void shouldSearchOnSingleField() throws Exception {


OResultSet resultSet = db OResultSet resultSet = db
.query("SELECT from Song where SEARCH_FIELDS('title', 'BELIEVE') = true"); .query("SELECT from Song where SEARCH_FIELDS(['title'], 'BELIEVE') = true");


assertThat(resultSet).hasSize(2); assertThat(resultSet).hasSize(2);


Expand All @@ -58,7 +57,7 @@ public void shouldSearchOnSingleFieldWithLeadingWildcard() throws Exception {
public void shouldSearhOnTwoFieldsInOR() throws Exception { public void shouldSearhOnTwoFieldsInOR() throws Exception {


OResultSet resultSet = db OResultSet resultSet = db
.query("SELECT from Song where SEARCH_FIELDS('title', 'BELIEVE') = true OR SEARCH_FIELDS('author', 'Bob') = true "); .query("SELECT from Song where SEARCH_FIELDS(['title'], 'BELIEVE') = true OR SEARCH_FIELDS(['author'], 'Bob') = true ");


assertThat(resultSet).hasSize(41); assertThat(resultSet).hasSize(41);
resultSet.close(); resultSet.close();
Expand All @@ -70,7 +69,7 @@ public void shouldSearhOnTwoFieldsInAND() throws Exception {


OResultSet resultSet = db OResultSet resultSet = db
.query( .query(
"SELECT from Song where SEARCH_FIELDS('title', 'tambourine') = true AND SEARCH_FIELDS('author', 'Bob') = true "); "SELECT from Song where SEARCH_FIELDS(['title'], 'tambourine') = true AND SEARCH_FIELDS(['author'], 'Bob') = true ");


assertThat(resultSet).hasSize(1); assertThat(resultSet).hasSize(1);
resultSet.close(); resultSet.close();
Expand All @@ -82,21 +81,21 @@ public void shouldSearchOnMultiFieldIndex() throws Exception {


OResultSet resultSet = db OResultSet resultSet = db
.query( .query(
"SELECT from Song where SEARCH_FIELDS('lyrics,description', '(description:happiness) (lyrics:sad) ') = true "); "SELECT from Song where SEARCH_FIELDS(['lyrics','description'], '(description:happiness) (lyrics:sad) ') = true ");


assertThat(resultSet).hasSize(2); assertThat(resultSet).hasSize(2);
resultSet.close(); resultSet.close();


resultSet = db resultSet = db
.query( .query(
"SELECT from Song where SEARCH_FIELDS('description,lyrics', '(description:happiness) (lyrics:sad) ') = true "); "SELECT from Song where SEARCH_FIELDS(['description','lyrics'], '(description:happiness) (lyrics:sad) ') = true ");


assertThat(resultSet).hasSize(2); assertThat(resultSet).hasSize(2);
resultSet.close(); resultSet.close();


resultSet = db resultSet = db
.query( .query(
"SELECT from Song where SEARCH_FIELDS('description', '(description:happiness) (lyrics:sad) ') = true "); "SELECT from Song where SEARCH_FIELDS(['description'], '(description:happiness) (lyrics:sad) ') = true ");


assertThat(resultSet).hasSize(2); assertThat(resultSet).hasSize(2);
resultSet.close(); resultSet.close();
Expand All @@ -108,7 +107,7 @@ public void shouldFindNothingWithWrongFieldName() throws Exception {


OResultSet resultSet = db OResultSet resultSet = db
.query( .query(
"SELECT from Song where SEARCH_FIELDS('wrongName', '(description:happiness) (lyrics:sad) ') = true "); "SELECT from Song where SEARCH_FIELDS(['wrongName'], '(description:happiness) (lyrics:sad) ') = true ");


assertThat(resultSet).hasSize(0); assertThat(resultSet).hasSize(0);
resultSet.close(); resultSet.close();
Expand Down
Expand Up @@ -53,7 +53,7 @@
*/ */
public class LuceneAutomaticBackupRestoreTest { public class LuceneAutomaticBackupRestoreTest {


private final static String DBNAME = "LuceneAutomaticBackupRestoreTest"; private final static String DBNAME = "OLuceneAutomaticBackupRestoreTest";
@Rule @Rule
public TemporaryFolder tempFolder = new TemporaryFolder(); public TemporaryFolder tempFolder = new TemporaryFolder();
private OrientDB orientDB; private OrientDB orientDB;
Expand Down Expand Up @@ -136,7 +136,7 @@ public void shouldBackupAndRestore() throws IOException, InterruptedException {


doc.field("targetDirectory", BACKUPDIR); doc.field("targetDirectory", BACKUPDIR);


doc.field("dbInclude", new String[] { "LuceneAutomaticBackupRestoreTest" }); doc.field("dbInclude", new String[] { "OLuceneAutomaticBackupRestoreTest" });


doc.field("firstTime", new SimpleDateFormat("HH:mm:ss").format(new Date(System.currentTimeMillis() + 2000))); doc.field("firstTime", new SimpleDateFormat("HH:mm:ss").format(new Date(System.currentTimeMillis() + 2000)));


Expand Down Expand Up @@ -208,7 +208,7 @@ public void shouldExportImport() throws IOException, InterruptedException {
doc.field("targetDirectory", BACKUPDIR); doc.field("targetDirectory", BACKUPDIR);
doc.field("mode", "EXPORT"); doc.field("mode", "EXPORT");


doc.field("dbInclude", new String[] { "LuceneAutomaticBackupRestoreTest" }); doc.field("dbInclude", new String[] { "OLuceneAutomaticBackupRestoreTest" });


doc.field("firstTime", new SimpleDateFormat("HH:mm:ss").format(new Date(System.currentTimeMillis() + 2000))); doc.field("firstTime", new SimpleDateFormat("HH:mm:ss").format(new Date(System.currentTimeMillis() + 2000)));


Expand Down
Expand Up @@ -71,12 +71,12 @@ public void testConcurrentInsertWithIndex() throws Exception {
for (int i = 0; i < THREADS + RTHREADS; ++i) for (int i = 0; i < THREADS + RTHREADS; ++i)
threads[i].start(); threads[i].start();


System.out.println("Started LuceneInsertReadMultithreadTest test, waiting for " + threads.length + " threads to complete..."); System.out.println("Started LuceneInsertReadMultithreadBaseTest test, waiting for " + threads.length + " threads to complete...");


for (int i = 0; i < THREADS + RTHREADS; ++i) for (int i = 0; i < THREADS + RTHREADS; ++i)
threads[i].join(); threads[i].join();


System.out.println("LuceneInsertReadMultithreadTest all threads completed"); System.out.println("LuceneInsertReadMultithreadBaseTest all threads completed");


OIndex idx = schema.getClass("City").getClassIndex("City.name"); OIndex idx = schema.getClass("City").getClassIndex("City.name");


Expand Down

0 comments on commit 3cd894f

Please sign in to comment.