Skip to content

Commit

Permalink
ut
Browse files Browse the repository at this point in the history
  • Loading branch information
turboFei committed Dec 22, 2024
1 parent 94c7820 commit 5cc3756
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
4 changes: 4 additions & 0 deletions project/CelebornBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ object Dependencies {
"org.fusesource.leveldbjni"
}
val leveldbJniAll = leveldbJniGroup % "leveldbjni-all" % leveldbJniVersion
val log4jApi = "org.apache.logging.log4j" % "log4j-api" % log4j2Version
val log4jCore = "org.apache.logging.log4j" % "log4j-core" % log4j2Version
val log4j12Api = "org.apache.logging.log4j" % "log4j-1.2-api" % log4j2Version
val log4jSlf4jImpl = "org.apache.logging.log4j" % "log4j-slf4j-impl" % log4j2Version
val lz4Java = "org.lz4" % "lz4-java" % lz4JavaVersion
Expand Down Expand Up @@ -629,6 +631,8 @@ object CelebornService {
Dependencies.jettyServer,
Dependencies.jettyServlet,
Dependencies.jettyProxy,
Dependencies.log4jApi,
Dependencies.log4jCore,
Dependencies.log4jSlf4jImpl % "test",
Dependencies.log4j12Api % "test",
Dependencies.h2 % "test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.apache.celeborn.server.common.http.api.v1

import javax.ws.rs.{Consumes, GET, Path, POST, Produces}
import javax.ws.rs.{Consumes, GET, POST, Produces, QueryParam}
import javax.ws.rs.core.MediaType

import io.swagger.v3.oas.annotations.media.{Content, Schema}
Expand All @@ -41,7 +41,7 @@ class LoggerResource extends ApiRequestContext {
schema = new Schema(implementation = classOf[LoggerLevel]))),
description = "Get the logger level.")
@GET
def getLoggerLevel(loggerName: String): LoggerLevel = {
def getLoggerLevel(@QueryParam("loggerName") loggerName: String): LoggerLevel = {
val logger = LogManager.getLogger(loggerName)
new LoggerLevel().loggerName(loggerName).level(logger.getLevel.toString)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ package org.apache.celeborn.server.common.http.api.v1

import java.net.URI
import javax.servlet.http.HttpServletResponse
import javax.ws.rs.client.Entity
import javax.ws.rs.core.{MediaType, UriBuilder}

import scala.collection.JavaConverters._

import org.apache.celeborn.rest.v1.model.{ConfResponse, ThreadStackResponse}
import org.apache.celeborn.rest.v1.model.{ConfResponse, LoggerLevel, ThreadStackResponse}
import org.apache.celeborn.server.common.http.HttpTestHelper

abstract class ApiV1BaseResourceSuite extends HttpTestHelper {
Expand All @@ -40,6 +41,48 @@ abstract class ApiV1BaseResourceSuite extends HttpTestHelper {
assert(response.readEntity(classOf[String]).contains("Dynamic configuration is disabled."))
}

test("logger resource") {
val loggerName = this.getClass.getName

// set logger level to INFO
val response = webTarget.path("logger")
.request(MediaType.APPLICATION_JSON)
.post(Entity.entity(
new LoggerLevel().loggerName(loggerName).level("INFO"),
MediaType.APPLICATION_JSON))
assert(HttpServletResponse.SC_OK == response.getStatus)

// check logger level is INFO
val response1 = webTarget.path("logger")
.queryParam("loggerName", loggerName)
.request(MediaType.APPLICATION_JSON).get()
assert(HttpServletResponse.SC_OK == response.getStatus)
val loggerLevel = response1.readEntity(classOf[LoggerLevel])
assert(loggerName == loggerLevel.getLoggerName)
assert(loggerLevel.getLevel == "INFO")
assert(log.isInfoEnabled)
assert(!log.isDebugEnabled)

// set logger level to DEBUG
val response2 = webTarget.path("logger")
.request(MediaType.APPLICATION_JSON)
.post(Entity.entity(
new LoggerLevel().loggerName(loggerName).level("DEBUG"),
MediaType.APPLICATION_JSON))
assert(HttpServletResponse.SC_OK == response2.getStatus)

// check logger level is DEBUG
val response3 = webTarget.path("logger")
.queryParam("loggerName", loggerName)
.request(MediaType.APPLICATION_JSON).get()
assert(HttpServletResponse.SC_OK == response.getStatus)
val loggerLevel2 = response3.readEntity(classOf[LoggerLevel])
assert(loggerName == loggerLevel2.getLoggerName)
assert(loggerLevel2.getLevel == "DEBUG")
assert(log.isInfoEnabled)
assert(log.isDebugEnabled)
}

test("thread_dump") {
val response = webTarget.path("thread_dump").request(MediaType.APPLICATION_JSON).get()
assert(HttpServletResponse.SC_OK == response.getStatus)
Expand Down

0 comments on commit 5cc3756

Please sign in to comment.