-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c82e56
commit e55633a
Showing
7 changed files
with
93 additions
and
20 deletions.
There are no files selected for viewing
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
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
33 changes: 33 additions & 0 deletions
33
src/integrationTest/kotlin/com/group4/ticketingservice/Event/EventControllerTest.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.group4.ticketingservice.Event | ||
|
||
import com.group4.ticketingservice.AbstractIntegrationTest | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc | ||
import org.springframework.cache.CacheManager | ||
import org.springframework.test.web.servlet.MockMvc | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders | ||
|
||
@AutoConfigureMockMvc | ||
class EventControllerTest : AbstractIntegrationTest() { | ||
@Autowired | ||
private lateinit var mockMvc: MockMvc | ||
|
||
@Autowired | ||
private lateinit var cacheManager: CacheManager | ||
|
||
@Test | ||
fun `getEvents caches the result`() { | ||
mockMvc.perform( | ||
MockMvcRequestBuilders.get("/events") | ||
.param("page", "0") | ||
.param("size", "10") | ||
|
||
) | ||
|
||
val cache = cacheManager.getCache("getEvents") | ||
val cachedValue = cache!!.get("0-10-id: DESC-null") | ||
|
||
assert(cachedValue != null) | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
src/main/kotlin/com/group4/ticketingservice/config/CacheConfig.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.group4.ticketingservice.config | ||
|
||
import org.springframework.cache.CacheManager | ||
import org.springframework.cache.annotation.CacheEvict | ||
import org.springframework.cache.annotation.EnableCaching | ||
import org.springframework.cache.concurrent.ConcurrentMapCache | ||
import org.springframework.cache.support.SimpleCacheManager | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.scheduling.annotation.Scheduled | ||
|
||
@Configuration | ||
@EnableCaching | ||
class CacheConfig { | ||
companion object { | ||
private const val EVENT_CACHE = "getEvents" | ||
} | ||
|
||
@Bean | ||
fun cacheManager(): CacheManager { | ||
val simpleCacheManager = SimpleCacheManager() | ||
simpleCacheManager.setCaches( | ||
listOf( | ||
ConcurrentMapCache(EVENT_CACHE) | ||
) | ||
) | ||
return simpleCacheManager | ||
} | ||
|
||
@CacheEvict(allEntries = true, value = [EVENT_CACHE]) | ||
@Scheduled(fixedDelay = 10 * 60 * 1000, initialDelay = 500) | ||
fun cacheEvict() {} | ||
} |
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
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