-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add all simple tests Signed-off-by: Sanjula Ganepola <[email protected]> * Add pool test Signed-off-by: Sanjula Ganepola <[email protected]> --------- Signed-off-by: Sanjula Ganepola <[email protected]>
- Loading branch information
1 parent
84eab31
commit 09d8e6b
Showing
6 changed files
with
214 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.github.mapapire; | ||
|
||
import io.github.mapapire.types.DaemonServer; | ||
|
||
import java.io.InputStream; | ||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
class MapepireTest { | ||
private static final String CONFIG_FILE = "config.properties"; | ||
public static DaemonServer creds; | ||
public static final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
@BeforeAll | ||
public static void setup() throws Exception { | ||
Properties properties = new Properties(); | ||
try (InputStream input = MapepireTest.class.getClassLoader().getResourceAsStream(CONFIG_FILE)) { | ||
if (input == null) { | ||
throw new IOException("Unable to find " + CONFIG_FILE); | ||
} | ||
properties.load(input); | ||
} | ||
|
||
List<String> keys = Arrays.asList("IBMI_HOST", "IBMI_USER", "IBMI_PASSWORD", "IBMI_PORT"); | ||
Map<String, String> secrets = new HashMap<>(); | ||
for (String key : keys) { | ||
String value = properties.getProperty(key); | ||
if (value.equals("")) { | ||
throw new Exception(key + " not set in config.properties"); | ||
} | ||
secrets.put(key, value); | ||
} | ||
|
||
String host = secrets.get(keys.get(0)); | ||
String user = secrets.get(keys.get(1)); | ||
String password = secrets.get(keys.get(2)); | ||
int port = Integer.parseInt(secrets.get(keys.get(3))); | ||
|
||
creds = new DaemonServer(host, port, user, password, true, ""); | ||
|
||
// TODO: Get certificate | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package io.github.mapapire; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.github.mapapire.types.QueryResult; | ||
|
||
class PoolTest extends MapepireTest { | ||
@Test | ||
@SuppressWarnings("unchecked") | ||
void simplePoolUsingPoolExecute() throws Exception { | ||
PoolOptions options = new PoolOptions(MapepireTest.creds, 5, 3); | ||
Pool pool = new Pool(options); | ||
pool.init().get(); | ||
|
||
List<CompletableFuture<QueryResult<Object>>> futuresA = new ArrayList<>(); | ||
for (int i = 0; i < 3; i++) { | ||
futuresA.add(pool.execute("values (job_name)")); | ||
} | ||
CompletableFuture<Void> allOfA = CompletableFuture.allOf(futuresA.toArray(new CompletableFuture[0])); | ||
allOfA.join(); | ||
|
||
List<String> jobNamesA = new ArrayList<>(); | ||
for (CompletableFuture<QueryResult<Object>> future : futuresA) { | ||
jobNamesA.add(((HashMap<String, String>) future.get().getData().get(0)).get("00001")); | ||
} | ||
|
||
assertEquals(3, jobNamesA.size()); | ||
assertEquals(3, pool.getActiveJobCount()); | ||
|
||
List<CompletableFuture<QueryResult<Object>>> futuresB = new ArrayList<>(); | ||
for (int i = 0; i < 15; i++) { | ||
futuresB.add(pool.execute("values (job_name)")); | ||
} | ||
CompletableFuture<Void> allOfB = CompletableFuture.allOf(futuresB.toArray(new CompletableFuture[0])); | ||
allOfB.join(); | ||
|
||
List<String> jobNamesB = new ArrayList<>(); | ||
for (CompletableFuture<QueryResult<Object>> future : futuresB) { | ||
jobNamesB.add(((HashMap<String, String>) future.get().getData().get(0)).get("00001")); | ||
} | ||
|
||
assertEquals(15, jobNamesB.size()); | ||
assertTrue(pool.getActiveJobCount() >= 3); | ||
assertTrue(pool.getActiveJobCount() <= 5); | ||
|
||
pool.end(); | ||
} | ||
} |
Oops, something went wrong.