Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
NehaSelvan1512 committed Sep 29, 2023
1 parent 6b100d9 commit 9a34ee8
Showing 1 changed file with 5 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
import org.junit.Test;
import org.polypheny.db.TestHelper;
import org.polypheny.db.adapter.DataStore;
import org.polypheny.db.algebra.AlgNode;
import org.polypheny.db.algebra.AlgRoot;
import org.polypheny.db.algebra.constant.Kind;
import org.polypheny.db.catalog.Catalog;
import org.polypheny.db.catalog.Catalog.NamespaceType;
import org.polypheny.db.catalog.Catalog.PlacementType;
Expand Down Expand Up @@ -61,7 +59,7 @@ public static void init() {
TestHelper testHelper = TestHelper.getInstance();
transaction = testHelper.getTransaction();
capture = new StreamCapture( transaction );
namespaceId = Helper.createNamespace( "testspace", NamespaceType.DOCUMENT );
namespaceId = Helper.createNamespace();
Helper.createCollection();
}

Expand Down Expand Up @@ -115,10 +113,9 @@ public void insertBooleanTest() {
//StreamCapture capture = new StreamCapture( transaction );
capture.insert( storingmsg );
BsonDocument result = Helper.filter( "{\"payload\":true}" ).get( 0 );
List<String> collection = Helper.scanCollection();

assertEquals( "testTopic", result.get( "topic" ).asString().getValue() );
assertEquals( true, result.get( "payload" ).asBoolean().getValue() );
assertTrue( result.get( "payload" ).asBoolean().getValue() );
assertEquals( "streamCaptureTest", result.get( "source" ).asString().getValue() );
}

Expand All @@ -133,7 +130,7 @@ public void insertJsonTest() {
assertEquals( "testTopic", result.get( "topic" ).asString().getValue() );
assertEquals( "streamCaptureTest", result.get( "source" ).asString().getValue() );
assertEquals( "value1", result.get( "payload" ).asDocument().get( "key1" ).asString().getValue() );
assertEquals( true, result.get( "payload" ).asDocument().get( "key2" ).asBoolean().getValue() );
assertTrue( result.get( "payload" ).asDocument().get( "key2" ).asBoolean().getValue() );
assertEquals( 3, result.get( "payload" ).asDocument().get( "key3" ).asInt32().getValue() );

}
Expand All @@ -146,7 +143,6 @@ public void insertArrayTest() {
//StreamCapture capture = new StreamCapture( transaction );
capture.insert( storingmsg );
BsonDocument result = Helper.filter( "{\"payload\":[1, 2, 3]}" ).get( 0 );
List<String> collection = Helper.scanCollection();
assertEquals( "testTopic", result.get( "topic" ).asString().getValue() );
BsonArray expectedPayload = new BsonArray();
expectedPayload.add( 0, new BsonInt32( 1 ) );
Expand Down Expand Up @@ -178,9 +174,9 @@ public void isBooleanTest() {

private static class Helper {

private static long createNamespace( String namespaceName, NamespaceType namespaceType ) {
private static long createNamespace() {
Catalog catalog = Catalog.getInstance();
long id = catalog.addNamespace( namespaceName, Catalog.defaultDatabaseId, Catalog.defaultUserId, namespaceType );
long id = catalog.addNamespace( "testspace", Catalog.defaultDatabaseId, Catalog.defaultUserId, NamespaceType.DOCUMENT );
try {
catalog.commit();
return id;
Expand Down Expand Up @@ -208,23 +204,6 @@ private static void createCollection() {
}


private static List<String> scanCollection() {
String sqlCollectionName = "testSpace" + "." + "testCollection";
Statement statement = transaction.createStatement();
AlgBuilder builder = AlgBuilder.create( statement );

AlgNode algNode = builder.docScan( statement, sqlCollectionName ).build();

AlgRoot root = AlgRoot.of( algNode, Kind.SELECT );
List<List<Object>> res = capture.executeAndTransformPolyAlg( root, statement, statement.getPrepareContext() );
List<String> result = new ArrayList<>();
for ( List<Object> objectsList : res ) {
result.add( objectsList.get( 0 ).toString() );
}
return result;
}


private static List<BsonDocument> filter( String query ) {
Statement statement = transaction.createStatement();
QueryParameters parameters = new MqlQueryParameters( String.format( "db.%s.find(%s)", "testCollection", query ), "testSpace", NamespaceType.DOCUMENT );
Expand Down

0 comments on commit 9a34ee8

Please sign in to comment.