1 /* <lambda>null2 * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 */ 4 5 package bytecode_test 6 7 import kotlinx.atomicfu.* 8 import kotlin.test.* 9 10 class TraceUseTest { 11 val trace = Trace(size = 64, format = TraceFormat { i, t -> "[$i$t]" } ) 12 val current = atomic(0, trace.named("current")) 13 14 @Test 15 fun testTraceUse() { 16 assertEquals(0, update(42)) 17 assertEquals(42, current.value) 18 } 19 20 fun update(x: Int): Int { 21 // custom trace message 22 trace { "calling update($x)" } 23 // automatic tracing of modification operations 24 return current.getAndAdd(x) 25 } 26 }