Compare commits

...

31 Commits

Author SHA1 Message Date
alfresco-build
6351782c1d [maven-release-plugin][skip ci] prepare release 23.4.0.52 2024-10-27 00:07:38 +00:00
Alfresco CI User
4c92868efb [force] Force release for 2024-10-27. 2024-10-27 00:04:27 +00:00
alfresco-build
2cca9ea11b [maven-release-plugin][skip ci] prepare for next development iteration 2024-10-25 11:06:31 +00:00
alfresco-build
e12001e4d1 [maven-release-plugin][skip ci] prepare release 23.4.0.51 2024-10-25 11:06:29 +00:00
dependabot[bot]
a57607f728 Bump org.springframework:spring-context from 6.1.13 to 6.1.14 (#3002)
Bumps [org.springframework:spring-context](https://github.com/spring-projects/spring-framework) from 6.1.13 to 6.1.14.
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](https://github.com/spring-projects/spring-framework/compare/v6.1.13...v6.1.14)

---
updated-dependencies:
- dependency-name: org.springframework:spring-context
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-10-25 10:49:56 +02:00
dependabot[bot]
a79af2cac0 Bump org.springframework.security:spring-security-bom (#3004)
Bumps [org.springframework.security:spring-security-bom](https://github.com/spring-projects/spring-security) from 6.3.3 to 6.3.4.
- [Release notes](https://github.com/spring-projects/spring-security/releases)
- [Changelog](https://github.com/spring-projects/spring-security/blob/main/RELEASE.adoc)
- [Commits](https://github.com/spring-projects/spring-security/compare/6.3.3...6.3.4)

---
updated-dependencies:
- dependency-name: org.springframework.security:spring-security-bom
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-10-25 10:14:37 +02:00
alfresco-build
be807c5b19 [maven-release-plugin][skip ci] prepare for next development iteration 2024-10-24 11:58:56 +00:00
alfresco-build
ae03e7076e [maven-release-plugin][skip ci] prepare release 23.4.0.50 2024-10-24 11:58:54 +00:00
Damian Ujma
26e394c398 ACS-6670 Change nodesSharedCache to fully-distributed (#3007) 2024-10-24 13:00:04 +02:00
alfresco-build
200aa95784 [maven-release-plugin][skip ci] prepare for next development iteration 2024-10-20 00:07:31 +00:00
alfresco-build
4eeabb3dbd [maven-release-plugin][skip ci] prepare release 23.4.0.49 2024-10-20 00:07:29 +00:00
Alfresco CI User
227bbe4fd8 [force] Force release for 2024-10-20. 2024-10-20 00:04:38 +00:00
alfresco-build
1461a04a3d [maven-release-plugin][skip ci] prepare for next development iteration 2024-10-16 13:08:10 +00:00
alfresco-build
52008dc139 [maven-release-plugin][skip ci] prepare release 23.4.0.48 2024-10-16 13:08:09 +00:00
rrajoria
f2a10052e4 Bump aos version 3.2.0-A1 (#2999) 2024-10-16 17:57:11 +05:30
alfresco-build
add64e0cb6 [maven-release-plugin][skip ci] prepare for next development iteration 2024-10-13 00:07:36 +00:00
alfresco-build
14511e2621 [maven-release-plugin][skip ci] prepare release 23.4.0.47 2024-10-13 00:07:34 +00:00
Alfresco CI User
42e0c93121 [force] Force release for 2024-10-13. 2024-10-13 00:04:33 +00:00
alfresco-build
715bc273ee [maven-release-plugin][skip ci] prepare for next development iteration 2024-10-11 12:42:44 +00:00
alfresco-build
812541870e [maven-release-plugin][skip ci] prepare release 23.4.0.46 2024-10-11 12:42:39 +00:00
dependabot[bot]
9aa5051826 Bump commons-io:commons-io from 2.16.1 to 2.17.0 (#2928)
Bumps commons-io:commons-io from 2.16.1 to 2.17.0.

---
updated-dependencies:
- dependency-name: commons-io:commons-io
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-10-11 14:00:02 +02:00
alfresco-build
54580b4aeb [maven-release-plugin][skip ci] prepare for next development iteration 2024-10-10 09:55:40 +00:00
alfresco-build
2b1b6091a3 [maven-release-plugin][skip ci] prepare release 23.4.0.45 2024-10-10 09:55:37 +00:00
Aleksandra Onych
74a147ab3f [ACS-8862] Bump Keycloak to 25.0.6 (#2983) 2024-10-10 11:13:08 +02:00
alfresco-build
07f0595f5a [maven-release-plugin][skip ci] prepare for next development iteration 2024-10-09 16:57:03 +00:00
alfresco-build
e3422ea6a5 [maven-release-plugin][skip ci] prepare release 23.4.0.44 2024-10-09 16:57:00 +00:00
Eva Vasques
f4103c242f MNT-24641 Avoid duplicate key error on content upload (#2984)
MNT-24641
* On createOrGetByValue in EntityLookupCache, also cache by value
* Created getCachedEntityByValue that attempt to retrieve the value only from cache
* On attempt to create content URL, first check cache before attempting to create in the database avoiding a duplicate key
2024-10-09 17:07:10 +01:00
alfresco-build
34fb5e9dd9 [maven-release-plugin][skip ci] prepare for next development iteration 2024-10-09 07:03:55 +00:00
alfresco-build
f6cf0670c1 [maven-release-plugin][skip ci] prepare release 23.4.0.43 2024-10-09 07:03:53 +00:00
rrajoria
c7bd036030 Update aos version (#2982)
Update aos version to 4.0.0-A1 with Spring 6.1 upgrade
2024-10-09 11:53:51 +05:30
alfresco-build
b20c573040 [maven-release-plugin][skip ci] prepare for next development iteration 2024-10-08 15:11:21 +00:00
29 changed files with 2041 additions and 1964 deletions

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-amps</artifactId>
<version>23.4.0.42</version>
<version>23.4.0.52</version>
</parent>
<modules>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-governance-services-community-parent</artifactId>
<version>23.4.0.42</version>
<version>23.4.0.52</version>
</parent>
<modules>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-governance-services-automation-community-repo</artifactId>
<version>23.4.0.42</version>
<version>23.4.0.52</version>
</parent>
<build>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-governance-services-community-parent</artifactId>
<version>23.4.0.42</version>
<version>23.4.0.52</version>
</parent>
<modules>

View File

@@ -8,7 +8,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-governance-services-community-repo-parent</artifactId>
<version>23.4.0.42</version>
<version>23.4.0.52</version>
</parent>
<properties>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-governance-services-community-repo-parent</artifactId>
<version>23.4.0.42</version>
<version>23.4.0.52</version>
</parent>
<build>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId>
<version>23.4.0.42</version>
<version>23.4.0.52</version>
</parent>
<modules>

View File

@@ -8,7 +8,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-amps</artifactId>
<version>23.4.0.42</version>
<version>23.4.0.52</version>
</parent>
<properties>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId>
<version>23.4.0.42</version>
<version>23.4.0.52</version>
</parent>
<dependencies>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId>
<version>23.4.0.42</version>
<version>23.4.0.52</version>
</parent>
<properties>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId>
<version>23.4.0.42</version>
<version>23.4.0.52</version>
</parent>
<dependencies>

View File

@@ -9,6 +9,6 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-packaging</artifactId>
<version>23.4.0.42</version>
<version>23.4.0.52</version>
</parent>
</project>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-packaging</artifactId>
<version>23.4.0.42</version>
<version>23.4.0.52</version>
</parent>
<properties>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId>
<version>23.4.0.42</version>
<version>23.4.0.52</version>
</parent>
<modules>

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-packaging</artifactId>
<version>23.4.0.42</version>
<version>23.4.0.52</version>
</parent>
<modules>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-tests</artifactId>
<version>23.4.0.42</version>
<version>23.4.0.52</version>
</parent>
<organization>

View File

@@ -9,7 +9,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-tests</artifactId>
<version>23.4.0.42</version>
<version>23.4.0.52</version>
</parent>
<developers>

View File

@@ -9,7 +9,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-tests</artifactId>
<version>23.4.0.42</version>
<version>23.4.0.52</version>
</parent>
<developers>

View File

@@ -8,7 +8,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-tests</artifactId>
<version>23.4.0.42</version>
<version>23.4.0.52</version>
</parent>
<properties>

View File

@@ -9,7 +9,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-tests</artifactId>
<version>23.4.0.42</version>
<version>23.4.0.52</version>
</parent>
<developers>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-packaging</artifactId>
<version>23.4.0.42</version>
<version>23.4.0.52</version>
</parent>
<properties>

12
pom.xml
View File

@@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>alfresco-community-repo</artifactId>
<version>23.4.0.42</version>
<version>23.4.0.52</version>
<packaging>pom</packaging>
<name>Alfresco Community Repo Parent</name>
@@ -57,8 +57,8 @@
<dependency.acs-event-model.version>0.0.33</dependency.acs-event-model.version>
<dependency.aspectj.version>1.9.22.1</dependency.aspectj.version>
<dependency.spring.version>6.1.13</dependency.spring.version>
<dependency.spring-security.version>6.3.3</dependency.spring-security.version>
<dependency.spring.version>6.1.14</dependency.spring.version>
<dependency.spring-security.version>6.3.4</dependency.spring-security.version>
<dependency.antlr.version>3.5.3</dependency.antlr.version>
<dependency.jackson.version>2.17.2</dependency.jackson.version>
<dependency.cxf.version>4.0.5</dependency.cxf.version>
@@ -69,7 +69,7 @@
<dependency.assertj.version>3.26.3</dependency.assertj.version>
<dependency.org-json.version>20240303</dependency.org-json.version>
<dependency.commons-dbcp.version>2.12.0</dependency.commons-dbcp.version>
<dependency.commons-io.version>2.16.1</dependency.commons-io.version>
<dependency.commons-io.version>2.17.0</dependency.commons-io.version>
<dependency.gson.version>2.11.0</dependency.gson.version>
<dependency.guava.version>33.3.1-jre</dependency.guava.version>
<dependency.httpclient.version>4.5.14</dependency.httpclient.version>
@@ -113,7 +113,7 @@
<dependency.jakarta-json-path.version>2.9.0</dependency.jakarta-json-path.version>
<dependency.json-smart.version>2.5.1</dependency.json-smart.version>
<alfresco.googledrive.version>4.1.0</alfresco.googledrive.version>
<alfresco.aos-module.version>3.1.0</alfresco.aos-module.version>
<alfresco.aos-module.version>3.2.0-A1</alfresco.aos-module.version>
<alfresco.api-explorer.version>23.3.0</alfresco.api-explorer.version> <!-- Also in alfresco-enterprise-share -->
<alfresco.maven-plugin.version>2.2.0</alfresco.maven-plugin.version>
@@ -154,7 +154,7 @@
<connection>scm:git:https://github.com/Alfresco/alfresco-community-repo.git</connection>
<developerConnection>scm:git:https://github.com/Alfresco/alfresco-community-repo.git</developerConnection>
<url>https://github.com/Alfresco/alfresco-community-repo</url>
<tag>23.4.0.42</tag>
<tag>23.4.0.52</tag>
</scm>
<distributionManagement>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId>
<version>23.4.0.42</version>
<version>23.4.0.52</version>
</parent>
<dependencies>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId>
<version>23.4.0.42</version>
<version>23.4.0.52</version>
</parent>
<dependencies>

View File

@@ -163,7 +163,7 @@ cache.node.nodesSharedCache.tx.statsEnabled=${caches.tx.statsEnabled}
cache.node.nodesSharedCache.maxItems=250000
cache.node.nodesSharedCache.timeToLiveSeconds=300
cache.node.nodesSharedCache.maxIdleSeconds=0
cache.node.nodesSharedCache.cluster.type=invalidating
cache.node.nodesSharedCache.cluster.type=fully-distributed
cache.node.nodesSharedCache.backup-count=1
cache.node.nodesSharedCache.eviction-policy=LRU
cache.node.nodesSharedCache.merge-policy=com.hazelcast.spi.merge.PutIfAbsentMergePolicy
@@ -709,4 +709,4 @@ cache.ldapInitialDirContextCache.cluster.type=fully-distributed
cache.ldapInitialDirContextCache.backup-count=1
cache.ldapInitialDirContextCache.eviction-policy=NONE
cache.ldapInitialDirContextCache.merge-policy=com.hazelcast.spi.merge.LatestUpdateMergePolicy
cache.ldapInitialDirContextCache.readBackupData=false
cache.ldapInitialDirContextCache.readBackupData=false

View File

@@ -21,391 +21,431 @@
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
* #L%
*/
package org.alfresco.repo.cache.lookup;
import java.sql.Savepoint;
import java.util.Map;
import java.util.TreeMap;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.alfresco.repo.cache.MemoryCache;
import org.alfresco.repo.cache.SimpleCache;
import org.alfresco.repo.cache.lookup.EntityLookupCache.EntityLookupCallbackDAO;
import org.alfresco.repo.domain.control.ControlDAO;
import org.alfresco.util.EqualsHelper;
import org.alfresco.util.Pair;
import org.mockito.Mockito;
import org.springframework.dao.DuplicateKeyException;
/**
* A cache for two-way lookups of database entities. These are characterized by having a unique
* key (perhaps a database ID) and a separate unique key that identifies the object.
* <p>
* The keys must have good <code>equals</code> and </code>hashCode</code> implementations and
* must respect the case-sensitivity of the use-case.
*
* @author Derek Hulley
* @since 3.2
*/
public class EntityLookupCacheTest extends TestCase implements EntityLookupCallbackDAO<Long, Object, String>
{
SimpleCache<Long, Object> cache;
private EntityLookupCache<Long, Object, String> entityLookupCacheA;
private EntityLookupCache<Long, Object, String> entityLookupCacheB;
private TreeMap<Long, String> database;
private ControlDAO controlDAO;
@Override
protected void setUp() throws Exception
{
cache = new MemoryCache<Long, Object>();
entityLookupCacheA = new EntityLookupCache<Long, Object, String>(cache, "A", this);
entityLookupCacheB = new EntityLookupCache<Long, Object, String>(cache, "B", this);
database = new TreeMap<Long, String>();
controlDAO = Mockito.mock(ControlDAO.class);
Mockito.when(controlDAO.createSavepoint(Mockito.anyString())).thenReturn(Mockito.mock(Savepoint.class));
}
public void testLookupsUsingIncorrectValue() throws Exception
{
try
{
// Keep the "database" empty
entityLookupCacheA.getByValue(this);
}
catch (AssertionFailedError e)
{
// Expected
}
}
public void testLookupAgainstEmpty() throws Exception
{
TestValue value = new TestValue("AAA");
Pair<Long, Object> entityPair = entityLookupCacheA.getByValue(value);
assertNull(entityPair);
assertTrue(database.isEmpty());
// Now do lookup or create
entityPair = entityLookupCacheA.getOrCreateByValue(value);
assertNotNull("Expected a value to be found", entityPair);
Long entityId = entityPair.getFirst();
assertTrue("Database ID should have been created", database.containsKey(entityId));
assertEquals("Database value incorrect", value.val, database.get(entityId));
// Do lookup or create again
entityPair = entityLookupCacheA.getOrCreateByValue(value);
assertNotNull("Expected a value to be found", entityPair);
assertEquals("Expected same entity ID", entityId, entityPair.getFirst());
// Look it up using the value
entityPair = entityLookupCacheA.getByValue(value);
assertNotNull("Lookup after create should work", entityPair);
// Look it up using the ID
entityPair = entityLookupCacheA.getByKey(entityId);
assertNotNull("Lookup by key should work after create", entityPair);
assertTrue("Looked-up type incorrect", entityPair.getSecond() instanceof TestValue);
assertEquals("Looked-up type value incorrect", value, entityPair.getSecond());
}
public void testLookupAgainstExisting() throws Exception
{
// Put some values in the "database"
createValue(new TestValue("AAA"));
createValue(new TestValue("BBB"));
createValue(new TestValue("CCC"));
// Look up by value
Pair<Long, Object> entityPair = entityLookupCacheA.getByValue(new TestValue("AAA"));
assertNotNull("Expected value to be found", entityPair);
assertEquals("ID is incorrect", Long.valueOf(1), entityPair.getFirst());
// Look up by ID
entityPair = entityLookupCacheA.getByKey(Long.valueOf(2));
assertNotNull("Expected value to be found", entityPair);
// Do lookup or create
entityPair = entityLookupCacheA.getByValue(new TestValue("CCC"));
assertNotNull("Expected value to be found", entityPair);
assertEquals("ID is incorrect", Long.valueOf(3), entityPair.getFirst());
}
public void testRegions() throws Exception
{
TestValue valueAAA = new TestValue("AAA");
Pair<Long, Object> entityPairAAA = entityLookupCacheA.getOrCreateByValue(valueAAA);
assertNotNull(entityPairAAA);
assertEquals("AAA", database.get(entityPairAAA.getFirst()));
assertEquals(2, cache.getKeys().size());
TestValue valueBBB = new TestValue("BBB");
Pair<Long, Object> entityPairBBB = entityLookupCacheB.getOrCreateByValue(valueBBB);
assertNotNull(entityPairBBB);
assertEquals("BBB", database.get(entityPairBBB.getFirst()));
assertEquals(4, cache.getKeys().size());
// Now cross-check against the caches and make sure that the cache
entityPairBBB = entityLookupCacheA.getByValue(valueBBB);
assertEquals(6, cache.getKeys().size());
entityPairBBB = entityLookupCacheB.getByValue(valueAAA);
assertEquals(8, cache.getKeys().size());
}
public void testNullLookups() throws Exception
{
TestValue valueNull = null;
Pair<Long, Object> entityPairNull = entityLookupCacheA.getOrCreateByValue(valueNull);
assertNotNull(entityPairNull);
assertTrue(database.containsKey(entityPairNull.getFirst()));
assertNull(database.get(entityPairNull.getFirst()));
assertEquals(2, cache.getKeys().size());
// Look it up again
Pair<Long, Object> entityPairCheck = entityLookupCacheA.getOrCreateByValue(valueNull);
assertNotNull(entityPairNull);
assertTrue(database.containsKey(entityPairNull.getFirst()));
assertNull(database.get(entityPairNull.getFirst()));
assertEquals(entityPairNull, entityPairCheck);
}
public void testGetOrCreate() throws Exception
{
TestValue valueOne = new TestValue(getName() + "-ONE");
Pair<Long, Object> entityPairOne = entityLookupCacheA.getOrCreateByValue(valueOne);
assertNotNull(entityPairOne);
Long id = entityPairOne.getFirst();
assertEquals(valueOne.val, database.get(id));
assertEquals(2, cache.getKeys().size());
Pair<Long, Object> entityPairOneCheck = entityLookupCacheA.getOrCreateByValue(valueOne);
assertNotNull(entityPairOneCheck);
assertEquals(id, entityPairOneCheck.getFirst());
}
public void testCreateOrGet() throws Exception
{
TestValue valueOne = new TestValue(getName() + "-ONE");
Pair<Long, Object> entityPairOne = entityLookupCacheA.createOrGetByValue(valueOne, controlDAO);
assertNotNull(entityPairOne);
Long id = entityPairOne.getFirst();
assertEquals(valueOne.val, database.get(id));
assertEquals(1, cache.getKeys().size());
Pair<Long, Object> entityPairOneCheck = entityLookupCacheA.createOrGetByValue(valueOne, controlDAO);
assertNotNull(entityPairOneCheck);
assertEquals(id, entityPairOneCheck.getFirst());
}
public void testUpdate() throws Exception
{
TestValue valueOne = new TestValue(getName() + "-ONE");
TestValue valueTwo = new TestValue(getName() + "-TWO");
Pair<Long, Object> entityPairOne = entityLookupCacheA.getOrCreateByValue(valueOne);
assertNotNull(entityPairOne);
Long id = entityPairOne.getFirst();
assertEquals(valueOne.val, database.get(id));
assertEquals(2, cache.getKeys().size());
// Update
int updateCount = entityLookupCacheA.updateValue(id, valueTwo);
assertEquals("Update count was incorrect.", 1, updateCount);
assertEquals(valueTwo.val, database.get(id));
assertEquals(2, cache.getKeys().size());
}
public void testDeleteByKey() throws Exception
{
TestValue valueOne = new TestValue(getName() + "-ONE");
Pair<Long, Object> entityPairOne = entityLookupCacheA.getOrCreateByValue(valueOne);
assertNotNull(entityPairOne);
Long id = entityPairOne.getFirst();
assertEquals(valueOne.val, database.get(id));
assertEquals(2, cache.getKeys().size());
// Delete
int deleteCount = entityLookupCacheA.deleteByKey(id);
assertEquals("Delete count was incorrect.", 1, deleteCount);
assertNull(database.get(id));
assertEquals(0, cache.getKeys().size());
}
public void testDeleteByValue() throws Exception
{
TestValue valueOne = new TestValue(getName() + "-ONE");
Pair<Long, Object> entityPairOne = entityLookupCacheA.getOrCreateByValue(valueOne);
assertNotNull(entityPairOne);
Long id = entityPairOne.getFirst();
assertEquals(valueOne.val, database.get(id));
assertEquals(2, cache.getKeys().size());
// Delete
int deleteCount = entityLookupCacheA.deleteByValue(valueOne);
assertEquals("Delete count was incorrect.", 1, deleteCount);
assertNull(database.get(id));
assertEquals(0, cache.getKeys().size());
}
public void testClear() throws Exception
{
TestValue valueOne = new TestValue(getName() + "-ONE");
Pair<Long, Object> entityPairOne = entityLookupCacheA.getOrCreateByValue(valueOne);
assertNotNull(entityPairOne);
Long id = entityPairOne.getFirst();
assertEquals(valueOne.val, database.get(id));
assertEquals(2, cache.getKeys().size());
// Clear it
entityLookupCacheA.clear();
assertEquals(valueOne.val, database.get(id)); // Must still be in database
assertEquals(0, cache.getKeys().size()); // ... but cache must be empty
}
/**
* Helper class to represent business object
*/
private static class TestValue
{
private final String val;
private TestValue(String val)
{
this.val = val;
}
@Override
public boolean equals(Object obj)
{
if (obj == null || !(obj instanceof TestValue))
{
return false;
}
return val.equals( ((TestValue)obj).val );
}
@Override
public int hashCode()
{
return val.hashCode();
}
}
public String getValueKey(Object value)
{
assertNotNull(value);
assertTrue(value instanceof TestValue);
String dbValue = ((TestValue)value).val;
return dbValue;
}
public Pair<Long, Object> findByKey(Long key)
{
assertNotNull(key);
String dbValue = database.get(key);
if (dbValue == null)
{
return null;
}
// Make a value object
TestValue value = new TestValue(dbValue);
return new Pair<Long, Object>(key, value);
}
public Pair<Long, Object> findByValue(Object value)
{
assertTrue(value == null || value instanceof TestValue);
String dbValue = (value == null) ? null : ((TestValue)value).val;
for (Map.Entry<Long, String> entry : database.entrySet())
{
if (EqualsHelper.nullSafeEquals(entry.getValue(), dbValue))
{
return new Pair<Long, Object>(entry.getKey(), entry.getValue());
}
}
return null;
}
/**
* Simulate creation of a new database entry
*/
public Pair<Long, Object> createValue(Object value)
{
assertTrue(value == null || value instanceof TestValue);
String dbValue = (value == null) ? null : ((TestValue)value).val;
// Kick out any duplicate values
if (database.containsValue(dbValue))
{
throw new DuplicateKeyException("Value is duplicated: " + value);
}
// Get the last key
Long lastKey = database.isEmpty() ? null : database.lastKey();
Long newKey = null;
if (lastKey == null)
{
newKey = Long.valueOf(1);
}
else
{
newKey = Long.valueOf(lastKey.longValue() + 1);
}
database.put(newKey, dbValue);
return new Pair<Long, Object>(newKey, value);
}
public int updateValue(Long key, Object value)
{
assertNotNull(key);
assertTrue(value == null || value instanceof TestValue);
// Find it
Pair<Long, Object> entityPair = findByKey(key);
if (entityPair == null)
{
return 0;
}
else
{
database.put(key, ((TestValue)value).val);
return 1;
}
}
public int deleteByKey(Long key)
{
assertNotNull(key);
if (database.containsKey(key))
{
database.remove(key);
return 1;
}
else
{
return 0;
}
}
public int deleteByValue(Object value)
{
assertTrue(value == null || value instanceof TestValue);
// Find it
Pair<Long, Object> entityPair = findByValue(value);
if (entityPair == null)
{
return 0;
}
else
{
database.remove(entityPair.getFirst());
return 1;
}
}
}
package org.alfresco.repo.cache.lookup;
import static org.junit.Assert.*;
import java.sql.Savepoint;
import java.util.Map;
import java.util.TreeMap;
import junit.framework.AssertionFailedError;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.dao.DuplicateKeyException;
import org.alfresco.repo.cache.MemoryCache;
import org.alfresco.repo.cache.SimpleCache;
import org.alfresco.repo.cache.lookup.EntityLookupCache.EntityLookupCallbackDAO;
import org.alfresco.repo.domain.control.ControlDAO;
import org.alfresco.util.EqualsHelper;
import org.alfresco.util.Pair;
/**
* A cache for two-way lookups of database entities. These are characterized by having a unique key (perhaps a database ID) and a separate unique key that identifies the object.
* <p>
* The keys must have good <code>equals</code> and </code>hashCode</code> implementations and must respect the case-sensitivity of the use-case.
*
* @author Derek Hulley
* @since 3.2
*/
public class EntityLookupCacheTest implements EntityLookupCallbackDAO<Long, Object, String>
{
SimpleCache<Long, Object> cache;
private EntityLookupCache<Long, Object, String> entityLookupCacheA;
private EntityLookupCache<Long, Object, String> entityLookupCacheB;
private TreeMap<Long, String> database;
private ControlDAO controlDAO;
@Before
protected void setUp() throws Exception
{
cache = new MemoryCache<Long, Object>();
entityLookupCacheA = new EntityLookupCache<Long, Object, String>(cache, "A", this);
entityLookupCacheB = new EntityLookupCache<Long, Object, String>(cache, "B", this);
database = new TreeMap<Long, String>();
controlDAO = Mockito.mock(ControlDAO.class);
Mockito.when(controlDAO.createSavepoint(Mockito.anyString())).thenReturn(Mockito.mock(Savepoint.class));
}
@Test
public void testLookupsUsingIncorrectValue() throws Exception
{
try
{
// Keep the "database" empty
entityLookupCacheA.getByValue(this);
}
catch (AssertionFailedError e)
{
// Expected
}
}
@Test
public void testLookupAgainstEmpty() throws Exception
{
TestValue value = new TestValue("AAA");
Pair<Long, Object> entityPair = entityLookupCacheA.getByValue(value);
assertNull(entityPair);
assertTrue(database.isEmpty());
// Now do lookup or create
entityPair = entityLookupCacheA.getOrCreateByValue(value);
assertNotNull("Expected a value to be found", entityPair);
Long entityId = entityPair.getFirst();
assertTrue("Database ID should have been created", database.containsKey(entityId));
assertEquals("Database value incorrect", value.val, database.get(entityId));
// Do lookup or create again
entityPair = entityLookupCacheA.getOrCreateByValue(value);
assertNotNull("Expected a value to be found", entityPair);
assertEquals("Expected same entity ID", entityId, entityPair.getFirst());
// Look it up using the value
entityPair = entityLookupCacheA.getByValue(value);
assertNotNull("Lookup after create should work", entityPair);
// Look it up using the ID
entityPair = entityLookupCacheA.getByKey(entityId);
assertNotNull("Lookup by key should work after create", entityPair);
assertTrue("Looked-up type incorrect", entityPair.getSecond() instanceof TestValue);
assertEquals("Looked-up type value incorrect", value, entityPair.getSecond());
}
@Test
public void testLookupAgainstExisting() throws Exception
{
// Put some values in the "database"
createValue(new TestValue("AAA"));
createValue(new TestValue("BBB"));
createValue(new TestValue("CCC"));
// Look up by value
Pair<Long, Object> entityPair = entityLookupCacheA.getByValue(new TestValue("AAA"));
assertNotNull("Expected value to be found", entityPair);
assertEquals("ID is incorrect", Long.valueOf(1), entityPair.getFirst());
// Look up by ID
entityPair = entityLookupCacheA.getByKey(Long.valueOf(2));
assertNotNull("Expected value to be found", entityPair);
// Do lookup or create
entityPair = entityLookupCacheA.getByValue(new TestValue("CCC"));
assertNotNull("Expected value to be found", entityPair);
assertEquals("ID is incorrect", Long.valueOf(3), entityPair.getFirst());
}
@Test
public void testRegions() throws Exception
{
TestValue valueAAA = new TestValue("AAA");
Pair<Long, Object> entityPairAAA = entityLookupCacheA.getOrCreateByValue(valueAAA);
assertNotNull(entityPairAAA);
assertEquals("AAA", database.get(entityPairAAA.getFirst()));
assertEquals(2, cache.getKeys().size());
TestValue valueBBB = new TestValue("BBB");
Pair<Long, Object> entityPairBBB = entityLookupCacheB.getOrCreateByValue(valueBBB);
assertNotNull(entityPairBBB);
assertEquals("BBB", database.get(entityPairBBB.getFirst()));
assertEquals(4, cache.getKeys().size());
// Now cross-check against the caches and make sure that the cache
entityPairBBB = entityLookupCacheA.getByValue(valueBBB);
assertEquals(6, cache.getKeys().size());
entityPairBBB = entityLookupCacheB.getByValue(valueAAA);
assertEquals(8, cache.getKeys().size());
}
@Test
public void testNullLookups() throws Exception
{
TestValue valueNull = null;
Pair<Long, Object> entityPairNull = entityLookupCacheA.getOrCreateByValue(valueNull);
assertNotNull(entityPairNull);
assertTrue(database.containsKey(entityPairNull.getFirst()));
assertNull(database.get(entityPairNull.getFirst()));
assertEquals(2, cache.getKeys().size());
// Look it up again
Pair<Long, Object> entityPairCheck = entityLookupCacheA.getOrCreateByValue(valueNull);
assertNotNull(entityPairNull);
assertTrue(database.containsKey(entityPairNull.getFirst()));
assertNull(database.get(entityPairNull.getFirst()));
assertEquals(entityPairNull, entityPairCheck);
}
@Test
public void testGetOrCreate() throws Exception
{
TestValue valueOne = new TestValue(getClass().getName() + "-ONE");
Pair<Long, Object> entityPairOne = entityLookupCacheA.getOrCreateByValue(valueOne);
assertNotNull(entityPairOne);
Long id = entityPairOne.getFirst();
assertEquals(valueOne.val, database.get(id));
assertEquals(2, cache.getKeys().size());
Pair<Long, Object> entityPairOneCheck = entityLookupCacheA.getOrCreateByValue(valueOne);
assertNotNull(entityPairOneCheck);
assertEquals(id, entityPairOneCheck.getFirst());
}
@Test
public void testCreateOrGet() throws Exception
{
TestValue valueOne = new TestValue(getClass().getName() + "-ONE");
Pair<Long, Object> entityPairOne = entityLookupCacheA.createOrGetByValue(valueOne, controlDAO);
assertNotNull(entityPairOne);
Long id = entityPairOne.getFirst();
assertEquals(valueOne.val, database.get(id));
// We cache both by value and by key, so we should have 2 entries
assertEquals(2, cache.getKeys().size());
Pair<Long, Object> entityPairOneCheck = entityLookupCacheA.createOrGetByValue(valueOne, controlDAO);
assertNotNull(entityPairOneCheck);
assertEquals(id, entityPairOneCheck.getFirst());
}
@Test
public void testUpdate() throws Exception
{
TestValue valueOne = new TestValue(getClass().getName() + "-ONE");
TestValue valueTwo = new TestValue(getClass().getName() + "-TWO");
Pair<Long, Object> entityPairOne = entityLookupCacheA.getOrCreateByValue(valueOne);
assertNotNull(entityPairOne);
Long id = entityPairOne.getFirst();
assertEquals(valueOne.val, database.get(id));
assertEquals(2, cache.getKeys().size());
// Update
int updateCount = entityLookupCacheA.updateValue(id, valueTwo);
assertEquals("Update count was incorrect.", 1, updateCount);
assertEquals(valueTwo.val, database.get(id));
assertEquals(2, cache.getKeys().size());
}
@Test
public void testDeleteByKey() throws Exception
{
TestValue valueOne = new TestValue(getClass().getName() + "-ONE");
Pair<Long, Object> entityPairOne = entityLookupCacheA.getOrCreateByValue(valueOne);
assertNotNull(entityPairOne);
Long id = entityPairOne.getFirst();
assertEquals(valueOne.val, database.get(id));
assertEquals(2, cache.getKeys().size());
// Delete
int deleteCount = entityLookupCacheA.deleteByKey(id);
assertEquals("Delete count was incorrect.", 1, deleteCount);
assertNull(database.get(id));
assertEquals(0, cache.getKeys().size());
}
@Test
public void testDeleteByValue() throws Exception
{
TestValue valueOne = new TestValue(getClass().getName() + "-ONE");
Pair<Long, Object> entityPairOne = entityLookupCacheA.getOrCreateByValue(valueOne);
assertNotNull(entityPairOne);
Long id = entityPairOne.getFirst();
assertEquals(valueOne.val, database.get(id));
assertEquals(2, cache.getKeys().size());
// Delete
int deleteCount = entityLookupCacheA.deleteByValue(valueOne);
assertEquals("Delete count was incorrect.", 1, deleteCount);
assertNull(database.get(id));
assertEquals(0, cache.getKeys().size());
}
@Test
public void testClear() throws Exception
{
TestValue valueOne = new TestValue(getClass().getName() + "-ONE");
Pair<Long, Object> entityPairOne = entityLookupCacheA.getOrCreateByValue(valueOne);
assertNotNull(entityPairOne);
Long id = entityPairOne.getFirst();
assertEquals(valueOne.val, database.get(id));
assertEquals(2, cache.getKeys().size());
// Clear it
entityLookupCacheA.clear();
assertEquals(valueOne.val, database.get(id)); // Must still be in database
assertEquals(0, cache.getKeys().size()); // ... but cache must be empty
}
@Test
public void testGetCachedValue() throws Exception
{
// Create a new value
TestValue valueCached = new TestValue(getClass().getName() + "-CACHED");
Pair<Long, Object> entityPairOne = entityLookupCacheA.createOrGetByValue(valueCached, controlDAO);
assertNotNull(entityPairOne);
Long id = entityPairOne.getFirst();
// We cache both by value and by key, so we should have 2 entries
assertEquals(2, cache.getKeys().size());
// Check the cache for the previously created value
Pair<Long, Object> entityPairCacheCheck = entityLookupCacheA.getCachedEntityByValue(valueCached);
assertNotNull(entityPairCacheCheck);
assertEquals(id, entityPairCacheCheck.getFirst());
// Clear the cache and attempt to retrieve it again
entityLookupCacheA.clear();
entityPairCacheCheck = entityLookupCacheA.getCachedEntityByValue(valueCached);
// Since we are only retrieving from cache, the value should not be found
assertNull(entityPairCacheCheck);
}
/**
* Helper class to represent business object
*/
private static class TestValue
{
private final String val;
private TestValue(String val)
{
this.val = val;
}
@Override
public boolean equals(Object obj)
{
if (obj == null || !(obj instanceof TestValue))
{
return false;
}
return val.equals(((TestValue) obj).val);
}
@Override
public int hashCode()
{
return val.hashCode();
}
}
public String getValueKey(Object value)
{
assertNotNull(value);
assertTrue(value instanceof TestValue);
String dbValue = ((TestValue) value).val;
return dbValue;
}
public Pair<Long, Object> findByKey(Long key)
{
assertNotNull(key);
String dbValue = database.get(key);
if (dbValue == null)
{
return null;
}
// Make a value object
TestValue value = new TestValue(dbValue);
return new Pair<Long, Object>(key, value);
}
public Pair<Long, Object> findByValue(Object value)
{
assertTrue(value == null || value instanceof TestValue);
String dbValue = (value == null) ? null : ((TestValue) value).val;
for (Map.Entry<Long, String> entry : database.entrySet())
{
if (EqualsHelper.nullSafeEquals(entry.getValue(), dbValue))
{
return new Pair<Long, Object>(entry.getKey(), entry.getValue());
}
}
return null;
}
/**
* Simulate creation of a new database entry
*/
public Pair<Long, Object> createValue(Object value)
{
assertTrue(value == null || value instanceof TestValue);
String dbValue = (value == null) ? null : ((TestValue) value).val;
// Kick out any duplicate values
if (database.containsValue(dbValue))
{
throw new DuplicateKeyException("Value is duplicated: " + value);
}
// Get the last key
Long lastKey = database.isEmpty() ? null : database.lastKey();
Long newKey = null;
if (lastKey == null)
{
newKey = Long.valueOf(1);
}
else
{
newKey = Long.valueOf(lastKey.longValue() + 1);
}
database.put(newKey, dbValue);
return new Pair<Long, Object>(newKey, value);
}
public int updateValue(Long key, Object value)
{
assertNotNull(key);
assertTrue(value == null || value instanceof TestValue);
// Find it
Pair<Long, Object> entityPair = findByKey(key);
if (entityPair == null)
{
return 0;
}
else
{
database.put(key, ((TestValue) value).val);
return 1;
}
}
public int deleteByKey(Long key)
{
assertNotNull(key);
if (database.containsKey(key))
{
database.remove(key);
return 1;
}
else
{
return 0;
}
}
public int deleteByValue(Object value)
{
assertTrue(value == null || value instanceof TestValue);
// Find it
Pair<Long, Object> entityPair = findByValue(value);
if (entityPair == null)
{
return 0;
}
else
{
database.remove(entityPair.getFirst());
return 1;
}
}
}

View File

@@ -59,7 +59,7 @@ services:
CLIENT_SSL_TRUST_STORE_TYPE: "JCEKS"
keycloak:
profiles: ["with-sso"]
image: quay.io/keycloak/keycloak:24.0.3
image: quay.io/keycloak/keycloak:25.0.6
environment:
- KEYCLOAK_ADMIN=admin
- KEYCLOAK_ADMIN_PASSWORD=admin