fixed concurrent incrementation problems
continuous-integration/drone/push Build is passing Details
continuous-integration/drone Build is passing Details

production
Override-6 2 years ago
parent 28aff516eb
commit e03ed9990a

@ -7,16 +7,16 @@ import java.util.concurrent.atomic.AtomicInteger
object IncrementHandler extends APIRequestHandler {
private val i = new AtomicInteger(0)
private val counter = new AtomicInteger(0)
def getCounter: Int = i.get()
def getCounter: Int = counter.get()
override def get(request: Request): Response = {
Response.json(s"{\"value\": $i}")
Response.json(s"{\"value\": ${counter.get()}}")
}
override def post(request: Request): Response = {
i.incrementAndGet()
val i = counter.incrementAndGet()
println(s"Counter is now $i")
Response.ok
}

@ -18,6 +18,8 @@ class IncrementRequestHandler {
Assertions.assertEquals(last + 1, IncrementHandler.getCounter)
}
@Test
def testGetIncrement(): Unit = {
val counter = IncrementHandler.getCounter