Skip to content

Commit

Permalink
add explicit GC cycle in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
quinchs committed Dec 14, 2023
1 parent 9b0bd4f commit 1d4a9bd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ public class Main {
private static final Logger logger = LoggerFactory.getLogger(Main.class);

public static void main(String[] args) throws Exception {
var client = new EdgeDBClient(EdgeDBClientConfig.builder()
try (var client = new EdgeDBClient(EdgeDBClientConfig.builder()
.withNamingStrategy(NamingStrategy.snakeCase())
.useFieldSetters(true)
.build()
).withModule("examples");
).withModule("examples")) {
runJavaExamples(client);

runJavaExamples(client);

logger.info("Examples complete");
logger.info("Examples complete");
}

client.close();
// run a GC cycle to ensure that any remaining dormant client instances get collected and closed.
System.gc();
}

private static void runJavaExamples(EdgeDBClient client) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,8 @@ object Main {
}
}
}

// run a GC cycle to ensure that any remaining dormant client instances get collected and closed.
System.gc();
}
}
2 changes: 1 addition & 1 deletion examples/scala-examples/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / scalaVersion := "3.1.3"

libraryDependencies ++= Seq(
"com.edgedb" % "driver" % "0.2.3" from "file:///" + System.getProperty("user.dir") + "/lib/com.edgedb.driver-0.2.3.jar",
"com.edgedb" % "driver" % "0.2.3" from "file:///" + System.getProperty("user.dir") + "/lib/com.edgedb.driver-0.4.3.jar",
"ch.qos.logback" % "logback-classic" % "1.4.7",
"ch.qos.logback" % "logback-core" % "1.4.7",
"com.fasterxml.jackson.core" % "jackson-databind" % "2.15.1",
Expand Down
23 changes: 14 additions & 9 deletions examples/scala-examples/src/main/scala/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@ import scala.concurrent.duration.Duration
import scala.concurrent.{Await, ExecutionContext, Future, blocking}
import scala.util.control.NonFatal
import ExecutionContext.Implicits.global
import scala.util.Using

@main
def main(): Unit = {
val logger = LoggerFactory.getLogger("Main")

val client = new EdgeDBClient(EdgeDBClientConfig.builder
.withNamingStrategy(NamingStrategy.snakeCase)
.useFieldSetters(true)
.build
).withModule("examples")

val examples = List(
AbstractTypes(),
BasicQueryFunctions(),
Expand All @@ -28,10 +23,20 @@ def main(): Unit = {
Transactions()
)

for (example <- examples)
Await.ready(runExample(logger, client, example), Duration.Inf)
Using(
new EdgeDBClient(EdgeDBClientConfig.builder
.withNamingStrategy(NamingStrategy.snakeCase)
.useFieldSetters(true)
.build
).withModule("examples")) { client =>
for (example <- examples)
Await.ready(runExample(logger, client, example), Duration.Inf)

logger.info("Examples complete!")
}

logger.info("Examples complete!")
// run a GC cycle to ensure that any remaining dormant client instances get collected and closed.
System.gc();
}

private def runExample(logger: Logger, client: EdgeDBClient, example: Example)(implicit context: ExecutionContext): Future[Unit] = {
Expand Down

0 comments on commit 1d4a9bd

Please sign in to comment.