Skip to content

Commit a32dcd7

Browse files
committed
DS-1723,DS-1841:
* Start implementing (ModifySpace) connector tests. Signed-off-by: mchrza <[email protected]>
1 parent be39ce2 commit a32dcd7

File tree

3 files changed

+112
-8
lines changed

3 files changed

+112
-8
lines changed

xyz-hub-test/src/main/resources/log4j2.properties

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
#
1616
# SPDX-License-Identifier: Apache-2.0
1717
# License-Filename: LICENSE
18-
rootLogger.level = OFF
18+
rootLogger.level = INFO
1919

20-
#packages = com.amazonaws.services.lambda.runtime.log4j2
21-
#appender.LAMBDA.type = Lambda
22-
#appender.LAMBDA.name = LAMBDA
23-
#appender.LAMBDA.layout.type = PatternLayout
24-
#appender.LAMBDA.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c:%.-4096m%n
25-
#
26-
#rootLogger.appenderRef.stdout.ref = LAMBDA
20+
packages = com.amazonaws.services.lambda.runtime.log4j2
21+
appender.LAMBDA.type = Lambda
22+
appender.LAMBDA.name = LAMBDA
23+
appender.LAMBDA.layout.type = PatternLayout
24+
appender.LAMBDA.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c:%.-4096m%n
25+
26+
rootLogger.appenderRef.stdout.ref = LAMBDA
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.here.xyz.hub.connectors;
2+
3+
import com.here.xyz.connectors.StorageConnector;
4+
import com.here.xyz.psql.NLConnector;
5+
import com.here.xyz.psql.PSQLXyzConnector;
6+
import com.here.xyz.psql.PSQLXyzNLConnector;
7+
import com.here.xyz.util.db.datasource.DatabaseSettings;
8+
9+
import static com.here.xyz.benchmarks.tools.PerformanceTestHelper.createDBSettings;
10+
import static com.here.xyz.benchmarks.tools.PerformanceTestHelper.initConnector;
11+
12+
public class EventBasedConnectorTest {
13+
private static final DatabaseSettings dbSettings =
14+
createDBSettings("localhost", "postgres", "postgres","password", 40);
15+
16+
protected static float xmin = 7.0f, ymin = 50.0f, xmax = 7.1f, ymax = 50.1f;
17+
18+
protected enum TARGET_CONNECTOR { PSQL_CONNECTOR, NL_CONNECTOR, PSQL_NL_CONNECTOR};
19+
20+
protected StorageConnector PSQL_CONNECTOR;
21+
protected StorageConnector PSQL_NL_CONNECTOR;
22+
protected StorageConnector NL_CONNECTOR;
23+
24+
protected StorageConnector loadConnector(TARGET_CONNECTOR targetConnector) throws Exception {
25+
if(PSQL_CONNECTOR != null)
26+
return PSQL_CONNECTOR;
27+
if(NL_CONNECTOR != null)
28+
return NL_CONNECTOR;
29+
if(PSQL_NL_CONNECTOR != null)
30+
return PSQL_NL_CONNECTOR;
31+
32+
return switch (targetConnector){
33+
case PSQL_CONNECTOR -> initConnector("TEST_" + targetConnector, new PSQLXyzConnector(), dbSettings);
34+
case PSQL_NL_CONNECTOR -> initConnector("TEST_" + targetConnector, new PSQLXyzNLConnector(), dbSettings);
35+
case NL_CONNECTOR -> initConnector("TEST_" + targetConnector, new NLConnector(), dbSettings)
36+
.withSeedingMode(false);
37+
};
38+
}
39+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.here.xyz.hub.connectors.psqlnlconnector;
2+
3+
import com.here.xyz.benchmarks.tools.PerformanceTestHelper;
4+
import com.here.xyz.connectors.StorageConnector;
5+
import com.here.xyz.events.ModifySpaceEvent;
6+
import com.here.xyz.events.UpdateStrategy;
7+
import com.here.xyz.events.WriteFeaturesEvent;
8+
import com.here.xyz.hub.connectors.EventBasedConnectorTest;
9+
import com.here.xyz.models.geojson.implementation.FeatureCollection;
10+
import com.here.xyz.models.hub.Space;
11+
import com.here.xyz.util.Random;
12+
import org.junit.Test;
13+
14+
import java.util.Map;
15+
import java.util.Set;
16+
17+
import static com.here.xyz.events.ModifySpaceEvent.Operation.CREATE;
18+
19+
public class ConnectorModifySpaceTest extends EventBasedConnectorTest {
20+
21+
@Test
22+
public void testCreateSpaceWithSearchableProperties() throws Exception {
23+
StorageConnector connector = loadConnector(TARGET_CONNECTOR.PSQL_NL_CONNECTOR);
24+
25+
String spaceName = this.getClass().getSimpleName() +"."+Random.randomAlpha(6);
26+
27+
Map<String, Boolean> searchableProperties = Map.of(
28+
"$alias1:[$.properties.refQuad]::scalar", true,
29+
"$alias2:[$.properties.globalVersion]::scalar", true,
30+
"$alias3:[$.properties.names[*].lang]::array", true,
31+
"$foo1.nested:[$.foo1.nested]::scalar", true
32+
// "$alias1:[$.properties.street.fc]::scalar", true,
33+
// "$alias2:[$.properties.names[*].lang]::array", true,
34+
// "$alias3:[$.properties.refQuad like_regex \"^0123\"]::scalar", true,
35+
36+
);
37+
38+
/* create space */
39+
ModifySpaceEvent modifySpaceEvent = new ModifySpaceEvent()
40+
.withSpaceDefinition(new Space()
41+
.withSearchableProperties(searchableProperties)
42+
.withId(spaceName)
43+
.withVersionsToKeep(1000)
44+
)
45+
.withSpace(spaceName)
46+
.withOperation(CREATE);
47+
connector.handleEvent(modifySpaceEvent);
48+
49+
/* write features */
50+
FeatureCollection fc = PerformanceTestHelper.generateRandomFeatureCollection(10, xmin, ymin, xmax, ymax, 100, false);
51+
52+
WriteFeaturesEvent writeFeaturesEvent = new WriteFeaturesEvent()
53+
.withModifications(Set.of(
54+
new WriteFeaturesEvent.Modification()
55+
.withFeatureData(fc)
56+
.withUpdateStrategy(UpdateStrategy.DEFAULT_UPDATE_STRATEGY)
57+
))
58+
.withSpace(spaceName)
59+
.withResponseDataExpected(false);
60+
connector.handleEvent(writeFeaturesEvent);
61+
62+
/* clean test resources */
63+
PerformanceTestHelper.deleteSpace(connector, spaceName);
64+
}
65+
}

0 commit comments

Comments
 (0)