From 07f5c6d9fc892f06f0bcc304170f585591a0c65e Mon Sep 17 00:00:00 2001 From: Abdellah El Morabit Date: Sun, 30 Nov 2025 16:10:36 +0100 Subject: feature: http server running successfully on port 8080 next steps are, throwing the stress tests into a running, tracking them, and starting the server to show the results --- src/main/scala/main/Main.scala | 34 +++++++++++--------- src/main/scala/main/domain/MemoryOperations.scala | 8 ++--- src/main/scala/main/infrastructure/Http.scala | 13 +------- .../scala/main/infrastructure/routes/Routes.scala | 16 ++++++++++ src/main/scala/main/services/Stress.scala | 37 ++++++++++++++++++++-- 5 files changed, 73 insertions(+), 35 deletions(-) create mode 100644 src/main/scala/main/infrastructure/routes/Routes.scala (limited to 'src') diff --git a/src/main/scala/main/Main.scala b/src/main/scala/main/Main.scala index 6baa0ce..b2d73ef 100644 --- a/src/main/scala/main/Main.scala +++ b/src/main/scala/main/Main.scala @@ -4,24 +4,28 @@ import main.domain._ import main.services._ import main.infrastructure._ import oshi._ -// import zio._ +import zio.http._ import java.lang.foreign._ +import zio._ -object Torque /* extends ZIOAppDefault */ { +object Torque extends ZIOAppDefault { - def main(args: Array[String]): Unit = MemoryAllocater.run() + def run = + Server.serve(routes) + .provide(Server.default) + .exitCode - // override def run: ZIO[ZIOAppArgs & Scope, Any, Any] = memoryExecution - // - // def memoryExecution: ZIO[Any, Throwable, Unit] = { - // - // - // for { - // _ <- ZIO.debug("started") - // f1 = MemoryAllocater.run() - // _ <- ZIO.debug("finished") - // - // } yield () - // } + // override def run: ZIO[ZIOAppArgs & Scope, Any, Any] = memoryExecution + // + // def memoryExecution: ZIO[Any, Throwable, Unit] = { + // + // + // for { + // _ <- ZIO.debug("started") + // f1 = MemoryAllocater.run() + // _ <- ZIO.debug("finished") + // + // } yield () + // } } diff --git a/src/main/scala/main/domain/MemoryOperations.scala b/src/main/scala/main/domain/MemoryOperations.scala index 8c2be88..548f071 100644 --- a/src/main/scala/main/domain/MemoryOperations.scala +++ b/src/main/scala/main/domain/MemoryOperations.scala @@ -29,13 +29,11 @@ class MemoryAllocater { * adding an offset so that the next piece of memory wont be overlapping with the one we just assigned * */ - def setValues(values: List[Int]): Unit = { + def setValues(values: List[Int], offset: Int): Unit = for i <- values.indices do memorySegment.set(ValueLayout.JAVA_INT, offset * i, values(i)) - for i <- 0 until 10 do memorySegment.set(ValueLayout.JAVA_INT, offset * i, List[i]) - } - - def getValues: Unit = (0 until 10).map(i => memorySegment.get(ValueLayout.JAVA_INT, offset * i)) + def getValues(offset: Int): Unit = (0 until 10).map(i => memorySegment.get(ValueLayout.JAVA_INT, offset * i)) def deallocateMemory: Unit = arena.close() def run(): Unit = println("address: " + memorySegment.address()) + } diff --git a/src/main/scala/main/infrastructure/Http.scala b/src/main/scala/main/infrastructure/Http.scala index cf9a6e1..1f1084b 100644 --- a/src/main/scala/main/infrastructure/Http.scala +++ b/src/main/scala/main/infrastructure/Http.scala @@ -1,7 +1,7 @@ package main.infrastructure import zio._ -import zio.http._ + /** * HTTP Handler @@ -10,14 +10,3 @@ import zio.http._ * * source: https://ziohttp.com */ -object Greeter extends ZIOAppDefault { - val routes = - Routes( - Method.GET / "stability" -> handler { (req: Request) => - val name = req.queryOrElse("", "World") - Response.text("stable!") - } - ) - - def run = Server.serve(routes).provide(Server.default) -} diff --git a/src/main/scala/main/infrastructure/routes/Routes.scala b/src/main/scala/main/infrastructure/routes/Routes.scala new file mode 100644 index 0000000..304e46e --- /dev/null +++ b/src/main/scala/main/infrastructure/routes/Routes.scala @@ -0,0 +1,16 @@ +package main.infrastructure + + +import zio._ +import zio.http._ + +val routes = Routes ( + + + Method.GET / Root -> handler(Response.text("Greetings at your services")), + Method.GET / "cpu" -> handler(Response.text("Greetings at your services")), + Method.GET / "ram" -> handler(Response.text("Greetings at your services")) + + +) + diff --git a/src/main/scala/main/services/Stress.scala b/src/main/scala/main/services/Stress.scala index 3709378..79cd041 100644 --- a/src/main/scala/main/services/Stress.scala +++ b/src/main/scala/main/services/Stress.scala @@ -10,8 +10,19 @@ enum Status: case PASS case FAIL -class Stress(val status: Status) { +abstract class Stress { + def runSequential: ZIO[Any, Throwable, Unit] + def runParallel: ZIO[Any, Throwable, Unit] + def setStatus: Unit + +} + +class StressCpu() extends Stress { + + var status: Status = Status.PASS + + def setStatus: Unit = status = Status.PASS def runCholeskyTest: ZIO[Any, Throwable, Unit] = { ZIO.attempt { @@ -26,14 +37,14 @@ class Stress(val status: Status) { }.catchAll { error => Console.printError(s"failed: $error")} } - def runSequential: ZIO[Any, Throwable, Unit] = { + override def runSequential: ZIO[Any, Throwable, Unit] = { Console.printLine("sequential test") *> runCholeskyTest *> runPrimeTest } - def runParallel: ZIO[Any, Throwable, Unit] = { + override def runParallel: ZIO[Any, Throwable, Unit] = { Console.printLine("CholeskyTest") *> (runCholeskyTest <&> runPrimeTest).unit @@ -41,3 +52,23 @@ class Stress(val status: Status) { } +class StressRam() extends Stress { + + var status: Status = Status.PASS + + override def setStatus: Unit = status = Status.PASS + + override def runSequential: ZIO[Any, Throwable, Unit] = { + + ZIO.attempt { + // TODO: + }.catchAll { error => Console.printError(s"failed: $error")} + + } + + override def runParallel : ZIO[Any, Throwable, Unit] = { + ZIO.attempt { + + }.catchAll { error => Console.printError(s"failed: $error")} + } +} -- cgit v1.2.3-70-g09d2