-
Notifications
You must be signed in to change notification settings - Fork 113
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
f232207
commit 1068da6
Showing
3 changed files
with
113 additions
and
3 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
entity-store/src/test/kotlin/jetbrains/exodus/entitystore/EntityIterableCacheAdapterTest.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,50 @@ | ||
/* | ||
* Copyright ${inceptionYear} - ${year} ${owner} | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package jetbrains.exodus.entitystore | ||
|
||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
|
||
|
||
class EntityIterableCacheAdapterTest { | ||
|
||
@Test | ||
fun `should create weighted cache`() { | ||
// Given | ||
// Use default config values | ||
val config = PersistentEntityStoreConfig() | ||
val maxCacheWeight = config.entityIterableCacheWeight | ||
|
||
// When | ||
val adapter = EntityIterableCacheAdapter.create(config) | ||
|
||
// Then | ||
assertEquals(maxCacheWeight, adapter.cache.size()) | ||
} | ||
|
||
@Test | ||
fun `should create sized cache for backward compatibility`() { | ||
// Given | ||
System.setProperty(PersistentEntityStoreConfig.ENTITY_ITERABLE_CACHE_SIZE, "100") | ||
val config = PersistentEntityStoreConfig() | ||
|
||
// When | ||
val adapter = EntityIterableCacheAdapter.create(config) | ||
|
||
// Then | ||
assertEquals(100, adapter.cache.size()) | ||
} | ||
} |
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
51 changes: 51 additions & 0 deletions
51
openAPI/src/test/kotlin/jetbrains/exodus/entitystore/PersistentEntityStoreCacheConfigTest.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,51 @@ | ||
/* | ||
* Copyright ${inceptionYear} - ${year} ${owner} | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package jetbrains.exodus.entitystore | ||
|
||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
|
||
class PersistentEntityStoreCacheConfigTest { | ||
|
||
@Test | ||
fun `should return default max cache weight`() { | ||
// Given | ||
val config = PersistentEntityStoreConfig() | ||
|
||
// When | ||
val maxCacheWeight = config.entityIterableCacheWeight | ||
|
||
// Then | ||
val maxMemory = Runtime.getRuntime().maxMemory() | ||
assertTrue(maxCacheWeight in 1..<maxMemory) | ||
} | ||
|
||
@Test | ||
fun `should calculate max cache weight from params`() { | ||
// Given | ||
System.setProperty(PersistentEntityStoreConfig.ENTITY_ITERABLE_CACHE_MEMORY_PERCENTAGE, "50") | ||
System.setProperty(PersistentEntityStoreConfig.ENTITY_ITERABLE_CACHE_ENTITY_WEIGHT, "8") | ||
val config = PersistentEntityStoreConfig() | ||
|
||
// When | ||
val maxCacheWeight = config.entityIterableCacheWeight | ||
|
||
// Then | ||
val maxMemory = Runtime.getRuntime().maxMemory() | ||
assertEquals(maxCacheWeight, (maxMemory * 50) / (100 * 8)) | ||
} | ||
} |