Skip to content

Commit

Permalink
Release 1.6.3 (#71)
Browse files Browse the repository at this point in the history
* Release 1.6.3

* adding unit test and cache control config
  • Loading branch information
puneetjaiswal committed Sep 19, 2019
1 parent 4cd9e18 commit d25507f
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 28 deletions.
2 changes: 1 addition & 1 deletion baseapp/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.lyft.data</groupId>
<artifactId>prestogateway-parent</artifactId>
<version>1.6.2-snapshot</version>
<version>1.6.3</version>
<relativePath>../</relativePath>
</parent>

Expand Down
30 changes: 18 additions & 12 deletions gateway-ha/pom.xml
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.lyft.data</groupId>
<artifactId>prestogateway-parent</artifactId>
<version>1.6.2-snapshot</version>
<version>1.6.3</version>
<relativePath>../</relativePath>
</parent>

Expand Down Expand Up @@ -50,17 +50,6 @@
<artifactId>mysql-connector-java</artifactId>
<version>${mysqlconnector.version}</version>
</dependency>
<!-- Test deps -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.192</version>
</dependency>
<!--db -->
<dependency>
<groupId>org.javalite</groupId>
Expand All @@ -72,6 +61,23 @@
<artifactId>ehcache</artifactId>
<version>${ehcache.version}</version>
</dependency>
<!-- Test deps -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>2.24.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.192</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Expand Up @@ -46,13 +46,7 @@ protected ProxyHandler getProxyHandler() {
.metrics()
.meter(getConfiguration().getRequestRouter().getName() + ".requests");
return new QueryIdCachingProxyHandler(
queryHistoryManager, routingManager, getApplicationPort(), requestMeter);
}

@Provides
@Singleton
public JdbcConnectionManager getConnectionManager() {
return this.connectionManager;
getQueryHistoryManager(), getRoutingManager(), getApplicationPort(), requestMeter);
}

@Provides
Expand Down Expand Up @@ -89,6 +83,18 @@ public QueryHistoryManager getQueryHistoryManager() {
return this.queryHistoryManager;
}

@Provides
@Singleton
public RoutingManager getRoutingManager() {
return this.routingManager;
}

@Provides
@Singleton
public JdbcConnectionManager getConnectionManager() {
return this.connectionManager;
}

@Provides
@Singleton
public List<ProxyServer> getProxyServers() {
Expand Down
17 changes: 17 additions & 0 deletions gateway-ha/src/main/resources/ehcache.xml
@@ -0,0 +1,17 @@
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
updateCheck="true" monitoring="autodetect">

<diskStore path="java.io.tmpdir"/>
<defaultCache
maxElementsInMemory="1000"
eternal="false"
timeToIdleSeconds="10"
timeToLiveSeconds="10"
overflowToDisk="true"
maxElementsOnDisk="10000"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="30"
memoryStoreEvictionPolicy="LRU"
/>
</ehcache>
@@ -1,26 +1,48 @@
package com.lyft.data.gateway.ha;

import com.lyft.data.gateway.ha.config.DataStoreConfiguration;
import com.lyft.data.gateway.ha.persistence.JdbcConnectionManager;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.javalite.activejdbc.Base;

@Slf4j
public class HaGatewayTestUtils {
@Data
protected static class TestConfig {
private String configFilePath;
private String h2DbFilePath;
}

public static String buildGatewayConfigPath(int routerPort) throws IOException {
public static void seedRequiredData(TestConfig testConfig) {
File baseDir = new File(System.getProperty("java.io.tmpdir"));
File tempH2DbDir = new File(baseDir, "h2db-" + System.currentTimeMillis());
tempH2DbDir.deleteOnExit();
String jdbcUrl = "jdbc:h2:" + testConfig.getH2DbFilePath();
DataStoreConfiguration db = new DataStoreConfiguration(jdbcUrl, "sa", "sa", "org.h2.Driver");
JdbcConnectionManager connectionManager = new JdbcConnectionManager(db);
connectionManager.open();
Base.exec(HaGatewayTestUtils.getResourceFileContent("gateway-ha-persistence.sql"));
connectionManager.close();
}

public static TestConfig buildGatewayConfigPath(int routerPort) throws IOException {
TestConfig testConfig = new TestConfig();
File baseDir = new File(System.getProperty("java.io.tmpdir"));
File tempCacheDir = new File(baseDir, "temp-" + System.currentTimeMillis());
tempCacheDir.deleteOnExit();

File tempH2DbDir = new File(baseDir, "h2db-" + System.currentTimeMillis());
tempH2DbDir.deleteOnExit();
testConfig.setH2DbFilePath(tempH2DbDir.getAbsolutePath());

String configStr =
getResourceFileContent("test_config_template.yaml")
getResourceFileContent("test-config-template.yml")
.replace("REQUEST_ROUTER_PORT", String.valueOf(routerPort))
.replace("CACHE_DIR", tempCacheDir.getAbsolutePath())
.replace("DB_FILE_PATH", tempH2DbDir.getAbsolutePath())
Expand All @@ -34,7 +56,9 @@ public static String buildGatewayConfigPath(int routerPort) throws IOException {
fw.append(configStr);
fw.flush();
log.info("Test Gateway Config \n[{}]", configStr);
return target.getAbsolutePath();
testConfig.setConfigFilePath(target.getAbsolutePath());
seedRequiredData(testConfig);
return testConfig;
}

public static String getResourceFileContent(String fileName) {
Expand Down
@@ -0,0 +1,79 @@
package com.lyft.data.gateway.ha;

import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class TestPrestoGatewayHaSingleBackend {
public static final String EXPECTED_RESPONSE = "{\"id\":\"testId\"}";
int backendPort = 20000 + (int) (Math.random() * 1000);
int routerPort = 21000 + (int) (Math.random() * 1000);

private WireMockServer backend =
new WireMockServer(WireMockConfiguration.options().port(backendPort));
private final OkHttpClient httpClient = new OkHttpClient();

@BeforeClass(alwaysRun = true)
public void setup() throws Exception {
backend.start();
backend.stubFor(
WireMock.post("/v1/statement")
.willReturn(
WireMock.aResponse()
.withBody(EXPECTED_RESPONSE)
.withHeader("Content-Encoding", "plain")
.withStatus(200)));

// Start Gateway
HaGatewayTestUtils.TestConfig testConfig =
HaGatewayTestUtils.buildGatewayConfigPath(routerPort);
String[] args = {"server", testConfig.getConfigFilePath()};
HaGatewayLauncher.main(args);
// Now populate the backend
RequestBody requestBody =
RequestBody.create(
MediaType.parse("application/json; charset=utf-8"),
"{"
+ " \"name\": \"presto1\",\n"
+ " \"proxyTo\": \"http://localhost:"
+ backendPort
+ "\",\n"
+ " \"active\": true,\n"
+ " \"routingGroup\": \"adhoc\"\n"
+ "}");
Request request =
new Request.Builder()
.url("http://localhost:" + routerPort + "/admin/entity?entityType=GATEWAY_BACKEND")
.post(requestBody)
.build();
Response response = httpClient.newCall(request).execute();
Assert.assertTrue(response.isSuccessful());
}

@Test
public void testRequestDelivery() throws Exception {
RequestBody requestBody =
RequestBody.create(MediaType.parse("application/json; charset=utf-8"), "SELECT 1");
Request request =
new Request.Builder()
.url("http://localhost:" + routerPort + "/v1/statement")
.post(requestBody)
.build();
Response response = httpClient.newCall(request).execute();
Assert.assertEquals(EXPECTED_RESPONSE, response.body().string());
}

@AfterClass(alwaysRun = true)
public void cleanup() {
backend.stop();
}
}
4 changes: 2 additions & 2 deletions gateway-ha/src/test/resources/test-config-template.yml
Expand Up @@ -13,8 +13,8 @@ server:

dataStore:
jdbcUrl: jdbc:h2:DB_FILE_PATH
user: root
password: root123
user: sa
password: sa
driver: org.h2.Driver

modules:
Expand Down
2 changes: 1 addition & 1 deletion gateway/pom.xml
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.lyft.data</groupId>
<artifactId>prestogateway-parent</artifactId>
<version>1.6.2-snapshot</version>
<version>1.6.3</version>
<relativePath>../</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -9,7 +9,7 @@
<artifactId>prestogateway-parent</artifactId>
<name>prestogateway-parent</name>
<packaging>pom</packaging>
<version>1.6.2-snapshot</version>
<version>1.6.3</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down
2 changes: 1 addition & 1 deletion proxyserver/pom.xml
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.lyft.data</groupId>
<artifactId>prestogateway-parent</artifactId>
<version>1.6.2-snapshot</version>
<version>1.6.3</version>
<relativePath>../</relativePath>
</parent>

Expand Down

0 comments on commit d25507f

Please sign in to comment.