Skip to content
This repository has been archived by the owner on Sep 12, 2018. It is now read-only.

Commit

Permalink
Update Android and iOS SDKs to reflect new named in memory functions.…
Browse files Browse the repository at this point in the history
… Utilize named in memory store in tests to ensure isolation when running.
  • Loading branch information
Emily Toop committed Aug 29, 2018
1 parent e1c2c9e commit b361ea8
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class InProgressBuilder extends PointerType {}
class EntityBuilder extends PointerType {}

Store store_open(String dbPath, RustError.ByReference err);
Store store_open_named_in_memory_store(String name, RustError.ByReference err);

void destroy(Pointer obj);
void uuid_destroy(Pointer obj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class Mentat extends RustObject<JNA.Store> {
private Mentat(JNA.Store rawPointer) { super(rawPointer); }

/**
* Open a connection to an in-memory Mentat Store.
* Open a connection to an anonymous in-memory Store.
*/
public static Mentat open() {
return open("");
Expand All @@ -51,6 +51,16 @@ public static Mentat open(String dbPath) {
return new Mentat(store);
}

/**
* Open a connection to a named in-memory Store.
* @param name The named to be given to the in memory store to open.
* @return An instance of Mentat connected to a named in memory store.
*/
public static Mentat namedInMemoryStore(String name) {
RustError.ByReference err = new RustError.ByReference();
return new Mentat(JNA.INSTANCE.store_open_named_in_memory_store(name, err));
}

/**
* Add an attribute to the cache. The {@link CacheDirection} determines how that attribute can be
* looked up.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ public TxReport transactSeattleData(Mentat mentat) {
return mentat.transact(seattleData);
}

public Mentat openAndInitializeCitiesStore() {
public Mentat openAndInitializeCitiesStore(String name) {
if (this.mentat == null) {
this.mentat = Mentat.open();
this.mentat = Mentat.namedInMemoryStore(name);
this.transactCitiesSchema(mentat);
this.transactSeattleData(mentat);
}
Expand Down Expand Up @@ -181,15 +181,15 @@ public DBSetupResult populateWithTypesSchema(Mentat mentat) {

@Test
public void transactingVocabularySucceeds() {
Mentat mentat = Mentat.open();
Mentat mentat = Mentat.namedInMemoryStore("transactingVocabularySucceeds");
TxReport schemaReport = this.transactCitiesSchema(mentat);
assertNotNull(schemaReport);
assertTrue(schemaReport.getTxId() > 0);
}

@Test
public void transactingEntitiesSucceeds() {
Mentat mentat = Mentat.open();
Mentat mentat = Mentat.namedInMemoryStore("transactingEntitiesSucceeds");
this.transactCitiesSchema(mentat);
TxReport dataReport = this.transactSeattleData(mentat);
assertNotNull(dataReport);
Expand All @@ -200,7 +200,7 @@ public void transactingEntitiesSucceeds() {

@Test
public void runScalarSucceeds() throws InterruptedException {
Mentat mentat = openAndInitializeCitiesStore();
Mentat mentat = openAndInitializeCitiesStore("runScalarSucceeds");
String query = "[:find ?n . :in ?name :where [(fulltext $ :community/name ?name) [[?e ?n]]]]";
final CountDownLatch expectation = new CountDownLatch(1);
mentat.query(query).bind("?name", "Wallingford").run(new ScalarResultHandler() {
Expand All @@ -216,7 +216,7 @@ public void handleValue(TypedValue value) {

@Test
public void runCollSucceeds() throws InterruptedException {
Mentat mentat = openAndInitializeCitiesStore();
Mentat mentat = openAndInitializeCitiesStore("runCollSucceeds");
String query = "[:find [?when ...] :where [_ :db/txInstant ?when] :order (asc ?when)]";
final CountDownLatch expectation = new CountDownLatch(1);
mentat.query(query).run(new CollResultHandler() {
Expand All @@ -234,7 +234,7 @@ public void handleList(CollResult list) {

@Test
public void runCollResultIteratorSucceeds() throws InterruptedException {
Mentat mentat = openAndInitializeCitiesStore();
Mentat mentat = openAndInitializeCitiesStore("runCollResultIteratorSucceeds");
String query = "[:find [?when ...] :where [_ :db/txInstant ?when] :order (asc ?when)]";
final CountDownLatch expectation = new CountDownLatch(1);
mentat.query(query).run(new CollResultHandler() {
Expand All @@ -253,7 +253,7 @@ public void handleList(CollResult list) {

@Test
public void runTupleSucceeds() throws InterruptedException {
Mentat mentat = openAndInitializeCitiesStore();
Mentat mentat = openAndInitializeCitiesStore("runTupleSucceeds");
String query = "[:find [?name ?cat]\n" +
" :where\n" +
" [?c :community/name ?name]\n" +
Expand All @@ -276,7 +276,7 @@ public void handleRow(TupleResult row) {

@Test
public void runRelIteratorSucceeds() throws InterruptedException {
Mentat mentat = openAndInitializeCitiesStore();
Mentat mentat = openAndInitializeCitiesStore("runRelIteratorSucceeds");
String query = "[:find ?name ?cat\n" +
" :where\n" +
" [?c :community/name ?name]\n" +
Expand Down Expand Up @@ -313,7 +313,7 @@ public void handleRows(RelResult rows) {

@Test
public void runRelSucceeds() throws InterruptedException {
Mentat mentat = openAndInitializeCitiesStore();
Mentat mentat = openAndInitializeCitiesStore("runRelSucceeds");
String query = "[:find ?name ?cat\n" +
" :where\n" +
" [?c :community/name ?name]\n" +
Expand Down Expand Up @@ -349,7 +349,7 @@ public void handleRows(RelResult rows) {

@Test
public void bindingLongValueSucceeds() throws InterruptedException {
Mentat mentat = Mentat.open();
Mentat mentat = Mentat.namedInMemoryStore("bindingLongValueSucceeds");
TxReport report = this.populateWithTypesSchema(mentat).dataReport;
final Long aEntid = report.getEntidForTempId("a");
String query = "[:find ?e . :in ?long :where [?e :foo/long ?long]]";
Expand All @@ -367,7 +367,7 @@ public void handleValue(TypedValue value) {

@Test
public void bindingRefValueSucceeds() throws InterruptedException {
Mentat mentat = Mentat.open();
Mentat mentat = Mentat.namedInMemoryStore("bindingRefValueSucceeds");
TxReport report = this.populateWithTypesSchema(mentat).dataReport;
long stringEntid = mentat.entIdForAttribute(":foo/string");
final Long bEntid = report.getEntidForTempId("b");
Expand All @@ -386,7 +386,7 @@ public void handleValue(TypedValue value) {

@Test
public void bindingRefKwValueSucceeds() throws InterruptedException {
Mentat mentat = Mentat.open();
Mentat mentat = Mentat.namedInMemoryStore("bindingRefKwValueSucceeds");
TxReport report = this.populateWithTypesSchema(mentat).dataReport;
String refKeyword = ":foo/string";
final Long bEntid = report.getEntidForTempId("b");
Expand All @@ -405,7 +405,7 @@ public void handleValue(TypedValue value) {

@Test
public void bindingKwValueSucceeds() throws InterruptedException {
Mentat mentat = Mentat.open();
Mentat mentat = Mentat.namedInMemoryStore("bindingKwValueSucceeds");
TxReport report = this.populateWithTypesSchema(mentat).dataReport;
final Long aEntid = report.getEntidForTempId("a");
String query = "[:find ?e . :in ?kw :where [?e :foo/keyword ?kw]]";
Expand All @@ -422,8 +422,8 @@ public void handleValue(TypedValue value) {
}

@Test
public void bindingDateValueSucceeds() throws InterruptedException {
Mentat mentat = Mentat.open();
public void bindingDateValueSucceeds() throws InterruptedException, ParseException {
Mentat mentat = Mentat.namedInMemoryStore("bindingDateValueSucceeds");
TxReport report = this.populateWithTypesSchema(mentat).dataReport;
final Long aEntid = report.getEntidForTempId("a");

Expand All @@ -445,7 +445,7 @@ public void handleRow(TupleResult row) {

@Test
public void bindingStringValueSucceeds() throws InterruptedException {
Mentat mentat = this.openAndInitializeCitiesStore();
Mentat mentat = this.openAndInitializeCitiesStore("bindingStringValueSucceeds");
String query = "[:find ?n . :in ?name :where [(fulltext $ :community/name ?name) [[?e ?n]]]]";
final CountDownLatch expectation = new CountDownLatch(1);
mentat.query(query).bind("?name", "Wallingford").run(new ScalarResultHandler() {
Expand All @@ -461,7 +461,7 @@ public void handleValue(TypedValue value) {

@Test
public void bindingUuidValueSucceeds() throws InterruptedException {
Mentat mentat = Mentat.open();
Mentat mentat = Mentat.namedInMemoryStore("bindingUuidValueSucceeds");
TxReport report = this.populateWithTypesSchema(mentat).dataReport;
final Long aEntid = report.getEntidForTempId("a");
String query = "[:find ?e . :in ?uuid :where [?e :foo/uuid ?uuid]]";
Expand All @@ -480,7 +480,7 @@ public void handleValue(TypedValue value) {

@Test
public void bindingBooleanValueSucceeds() throws InterruptedException {
Mentat mentat = Mentat.open();
Mentat mentat = Mentat.namedInMemoryStore("bindingBooleanValueSucceeds");
TxReport report = this.populateWithTypesSchema(mentat).dataReport;
final Long aEntid = report.getEntidForTempId("a");
String query = "[:find ?e . :in ?bool :where [?e :foo/boolean ?bool]]";
Expand All @@ -499,7 +499,7 @@ public void handleValue(TypedValue value) {

@Test
public void bindingDoubleValueSucceeds() throws InterruptedException {
Mentat mentat = Mentat.open();
Mentat mentat = Mentat.namedInMemoryStore("bindingDoubleValueSucceeds");
TxReport report = this.populateWithTypesSchema(mentat).dataReport;
final Long aEntid = report.getEntidForTempId("a");
String query = "[:find ?e . :in ?double :where [?e :foo/double ?double]]";
Expand All @@ -517,7 +517,7 @@ public void handleValue(TypedValue value) {

@Test
public void typedValueConvertsToLong() throws InterruptedException {
Mentat mentat = Mentat.open();
Mentat mentat = Mentat.namedInMemoryStore("typedValueConvertsToLong");
TxReport report = this.populateWithTypesSchema(mentat).dataReport;
final Long aEntid = report.getEntidForTempId("a");
String query = "[:find ?v . :in ?e :where [?e :foo/long ?v]]";
Expand All @@ -536,7 +536,7 @@ public void handleValue(TypedValue value) {

@Test
public void typedValueConvertsToRef() throws InterruptedException {
Mentat mentat = Mentat.open();
Mentat mentat = Mentat.namedInMemoryStore("typedValueConvertsToRef");
TxReport report = this.populateWithTypesSchema(mentat).dataReport;
final Long aEntid = report.getEntidForTempId("a");
String query = "[:find ?e . :where [?e :foo/long 25]]";
Expand All @@ -555,7 +555,7 @@ public void handleValue(TypedValue value) {

@Test
public void typedValueConvertsToKeyword() throws InterruptedException {
Mentat mentat = Mentat.open();
Mentat mentat = Mentat.namedInMemoryStore("typedValueConvertsToKeyword");
TxReport report = this.populateWithTypesSchema(mentat).dataReport;
final Long aEntid = report.getEntidForTempId("a");
String query = "[:find ?v . :in ?e :where [?e :foo/keyword ?v]]";
Expand All @@ -574,7 +574,7 @@ public void handleValue(TypedValue value) {

@Test
public void typedValueConvertsToBoolean() throws InterruptedException {
Mentat mentat = Mentat.open();
Mentat mentat = Mentat.namedInMemoryStore("typedValueConvertsToBoolean");
TxReport report = this.populateWithTypesSchema(mentat).dataReport;
final Long aEntid = report.getEntidForTempId("a");
String query = "[:find ?v . :in ?e :where [?e :foo/boolean ?v]]";
Expand All @@ -593,7 +593,7 @@ public void handleValue(TypedValue value) {

@Test
public void typedValueConvertsToDouble() throws InterruptedException {
Mentat mentat = Mentat.open();
Mentat mentat = Mentat.namedInMemoryStore("typedValueConvertsToDouble");
TxReport report = this.populateWithTypesSchema(mentat).dataReport;
final Long aEntid = report.getEntidForTempId("a");
String query = "[:find ?v . :in ?e :where [?e :foo/double ?v]]";
Expand All @@ -612,7 +612,7 @@ public void handleValue(TypedValue value) {

@Test
public void typedValueConvertsToDate() throws InterruptedException, ParseException {
Mentat mentat = Mentat.open();
Mentat mentat = Mentat.namedInMemoryStore("typedValueConvertsToDate");
TxReport report = this.populateWithTypesSchema(mentat).dataReport;
final Long aEntid = report.getEntidForTempId("a");
String query = "[:find ?v . :in ?e :where [?e :foo/instant ?v]]";
Expand All @@ -638,7 +638,7 @@ public void handleValue(TypedValue value) {

@Test
public void typedValueConvertsToString() throws InterruptedException {
Mentat mentat = Mentat.open();
Mentat mentat = Mentat.namedInMemoryStore("typedValueConvertsToString");
TxReport report = this.populateWithTypesSchema(mentat).dataReport;
final Long aEntid = report.getEntidForTempId("a");
String query = "[:find ?v . :in ?e :where [?e :foo/string ?v]]";
Expand All @@ -657,7 +657,7 @@ public void handleValue(TypedValue value) {

@Test
public void typedValueConvertsToUUID() throws InterruptedException {
Mentat mentat = Mentat.open();
Mentat mentat = Mentat.namedInMemoryStore("typedValueConvertsToUUID");
TxReport report = this.populateWithTypesSchema(mentat).dataReport;
final Long aEntid = report.getEntidForTempId("a");
String query = "[:find ?v . :in ?e :where [?e :foo/uuid ?v]]";
Expand All @@ -676,8 +676,8 @@ public void handleValue(TypedValue value) {
}

@Test
public void valueForAttributeOfEntitySucceeds() {
Mentat mentat = Mentat.open();
public void valueForAttributeOfEntitySucceeds() throws InterruptedException {
Mentat mentat = Mentat.namedInMemoryStore("valueForAttributeOfEntitySucceeds");
TxReport report = this.populateWithTypesSchema(mentat).dataReport;
final Long aEntid = report.getEntidForTempId("a");
TypedValue value = mentat.valueForAttributeOfEntity(":foo/long", aEntid);
Expand All @@ -695,15 +695,15 @@ public void entidForAttributeSucceeds() {

@Test
public void testInProgressTransact() {
Mentat mentat = Mentat.open();
Mentat mentat = Mentat.namedInMemoryStore("testInProgressTransact");
TxReport report = this.populateWithTypesSchema(mentat).dataReport;
assertNotNull(report);

}

@Test
public void testInProgressRollback() {
Mentat mentat = Mentat.open();
Mentat mentat = Mentat.namedInMemoryStore("testInProgressRollback");
TxReport report = this.populateWithTypesSchema(mentat).dataReport;
assertNotNull(report);
long aEntid = report.getEntidForTempId("a");
Expand All @@ -721,7 +721,7 @@ public void testInProgressRollback() {

@Test
public void testInProgressEntityBuilder() throws InterruptedException {
Mentat mentat = Mentat.open();
Mentat mentat = Mentat.namedInMemoryStore("testInProgressEntityBuilder");
DBSetupResult reports = this.populateWithTypesSchema(mentat);
long bEntid = reports.dataReport.getEntidForTempId("b");
final long longEntid = reports.schemaReport.getEntidForTempId("l");
Expand Down Expand Up @@ -795,7 +795,7 @@ public void handleRow(TupleResult row) {

@Test
public void testEntityBuilderForEntid() throws InterruptedException {
Mentat mentat = Mentat.open();
Mentat mentat = Mentat.namedInMemoryStore("testEntityBuilderForEntid");
DBSetupResult reports = this.populateWithTypesSchema(mentat);
long bEntid = reports.dataReport.getEntidForTempId("b");
final long longEntid = reports.schemaReport.getEntidForTempId("l");
Expand Down Expand Up @@ -869,7 +869,7 @@ public void handleRow(TupleResult row) {

@Test
public void testEntityBuilderForTempid() throws InterruptedException {
Mentat mentat = Mentat.open();
Mentat mentat = Mentat.namedInMemoryStore("testEntityBuilderForTempid");
DBSetupResult reports = this.populateWithTypesSchema(mentat);
final long longEntid = reports.schemaReport.getEntidForTempId("l");

Expand Down Expand Up @@ -922,7 +922,7 @@ public void handleRow(TupleResult row) {

@Test
public void testInProgressBuilderTransact() throws InterruptedException {
Mentat mentat = Mentat.open();
Mentat mentat = Mentat.namedInMemoryStore("testInProgressBuilderTransact");
DBSetupResult reports = this.populateWithTypesSchema(mentat);
long aEntid = reports.dataReport.getEntidForTempId("a");
long bEntid = reports.dataReport.getEntidForTempId("b");
Expand Down Expand Up @@ -984,7 +984,7 @@ public void handleRow(TupleResult row) {

@Test
public void testEntityBuilderTransact() throws InterruptedException {
Mentat mentat = Mentat.open();
Mentat mentat = Mentat.namedInMemoryStore("testEntityBuilderTransact");
DBSetupResult reports = this.populateWithTypesSchema(mentat);
long aEntid = reports.dataReport.getEntidForTempId("a");
long bEntid = reports.dataReport.getEntidForTempId("b");
Expand Down Expand Up @@ -1047,7 +1047,7 @@ public void handleRow(TupleResult row) {

@Test
public void testEntityBuilderRetract() throws InterruptedException {
Mentat mentat = Mentat.open();
Mentat mentat = Mentat.namedInMemoryStore("testEntityBuilderRetract");
DBSetupResult reports = this.populateWithTypesSchema(mentat);
long bEntid = reports.dataReport.getEntidForTempId("b");
final long longEntid = reports.schemaReport.getEntidForTempId("l");
Expand Down Expand Up @@ -1111,7 +1111,7 @@ public void handleRow(TupleResult row) {

@Test
public void testInProgressBuilderRetract() throws InterruptedException {
Mentat mentat = Mentat.open();
Mentat mentat = Mentat.namedInMemoryStore("testInProgressBuilderRetract");
DBSetupResult reports = this.populateWithTypesSchema(mentat);
long bEntid = reports.dataReport.getEntidForTempId("b");
final long longEntid = reports.schemaReport.getEntidForTempId("l");
Expand Down Expand Up @@ -1180,7 +1180,7 @@ public void testCaching() throws InterruptedException {
" [?neighborhood :neighborhood/district ?d]\n" +
" [?d :district/name ?district]]";

Mentat mentat = openAndInitializeCitiesStore();
Mentat mentat = openAndInitializeCitiesStore("testCaching");

final CountDownLatch expectation1 = new CountDownLatch(1);
final QueryTimer uncachedTimer = new QueryTimer();
Expand Down
11 changes: 11 additions & 0 deletions sdks/swift/Mentat/Mentat/Mentat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ open class Mentat: RustObject {
public class func open(storeURI: String = "") throws -> Mentat {
return Mentat(raw: try RustError.unwrap({err in store_open(storeURI, err) }))
}

/**
Open a connection to a Store in a given location.
If the store does not already exist, one will be created.

- Parameter storeURI: The URI as a String of the store to open.
If no store URI is provided, an in-memory store will be opened.
*/
public convenience init(namedInMemoryStore name: String) throws {
self.init(raw: try RustError.unwrap({err in store_open_named_in_memory_store(name, err) }))
}

/**
Add an attribute to the cache. The {@link CacheDirection} determines how that attribute can be
Expand Down
1 change: 1 addition & 0 deletions sdks/swift/Mentat/Mentat/store.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ typedef NS_ENUM(NSInteger, ValueType) {

// Store
struct Store*_Nonnull store_open(const char*_Nonnull uri, struct RustError* _Nonnull error);
struct Store*_Nonnull store_open_named_in_memory_store(const char*_Nonnull name, struct RustError* _Nonnull error);

// Destructors.
void destroy(void* _Nullable obj);
Expand Down
Loading

0 comments on commit b361ea8

Please sign in to comment.