Last active
August 18, 2022 05:10
-
-
Save stella6767/1fbdffbb1b1cea9badc1c87c81adef08 to your computer and use it in GitHub Desktop.
동시성 테스트
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun tokenRepositoyTest(){ | |
val tokenRepository:TokenRepository = MemoryTokenRepositoryImpl() | |
val numberOfThreads = 1000 | |
val service = Executors.newFixedThreadPool(10) | |
val latch = CountDownLatch(numberOfThreads) | |
for ( index in 1..numberOfThreads){ | |
service.submit { | |
tokenRepository.save(index.toString(), "${index.toString()}" ) | |
latch.countDown() | |
} | |
} | |
latch.await() | |
val results1 = tokenRepository.findAll().map { it.toInt() }.sorted() | |
Assertions.assertThat(results1.size).isEqualTo(numberOfThreads); | |
log.info { "size1: ${results1.size}" } | |
//tokenRepository.clearStore() | |
//Thread.sleep(5000) | |
for (s in results1) { | |
val remove = tokenRepository.remove(s.toString()) | |
if (s == 500) { | |
break | |
} | |
//log.info { "remove: $remove" } | |
} | |
val results2 = tokenRepository.findAll().map { it.toInt() }.sorted() | |
log.info { "size2: ${results2.size}" } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment