From c1782e2e7527bf30bac534c08ea9056c570631c9 Mon Sep 17 00:00:00 2001 From: CrowleyRajapakse Date: Thu, 27 Aug 2020 11:59:37 +0530 Subject: [PATCH] Fix failing unique key contraint and intermittent test failure --- .../registry/core/jdbc/dao/JDBCPathCache.java | 2 +- .../core/test/jdbc/CustomQueryTest.java | 25 ++++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/core/org.wso2.carbon.registry.core/src/main/java/org/wso2/carbon/registry/core/jdbc/dao/JDBCPathCache.java b/core/org.wso2.carbon.registry.core/src/main/java/org/wso2/carbon/registry/core/jdbc/dao/JDBCPathCache.java index 8633e59fe34..9db145b8572 100644 --- a/core/org.wso2.carbon.registry.core/src/main/java/org/wso2/carbon/registry/core/jdbc/dao/JDBCPathCache.java +++ b/core/org.wso2.carbon.registry.core/src/main/java/org/wso2/carbon/registry/core/jdbc/dao/JDBCPathCache.java @@ -133,7 +133,7 @@ public int addEntry(String path, int parentPathId) throws SQLException, Registry } } } catch (SQLException e) { - if (e instanceof SQLIntegrityConstraintViolationException) { + if (e instanceof SQLIntegrityConstraintViolationException || "23505".equals(e.getSQLState())) { if (log.isDebugEnabled()) { log.debug("Failed to insert due to already exist in database : " + path); } diff --git a/core/org.wso2.carbon.registry.core/src/test/java/org/wso2/carbon/registry/core/test/jdbc/CustomQueryTest.java b/core/org.wso2.carbon.registry.core/src/test/java/org/wso2/carbon/registry/core/test/jdbc/CustomQueryTest.java index c3cdd390534..ddef661cd26 100644 --- a/core/org.wso2.carbon.registry.core/src/test/java/org/wso2/carbon/registry/core/test/jdbc/CustomQueryTest.java +++ b/core/org.wso2.carbon.registry.core/src/test/java/org/wso2/carbon/registry/core/test/jdbc/CustomQueryTest.java @@ -204,12 +204,13 @@ public void test4CustomQueryResultsOrderForComments() throws RegistryException { try { registry.addComment("/test/comments/r1x", new Comment("commentXX1 on this resource :)")); - Thread.sleep(500); + Thread.sleep(2000); registry.addComment("/test/comments/r1x", new Comment("commentXX2 on this resource :)")); - Thread.sleep(500); + Thread.sleep(2000); registry.addComment("/test/comments/r1x", new Comment("commentXX3 on this resource :)")); - Thread.sleep(500); + Thread.sleep(2000); registry.addComment("/test/comments/r1x", new Comment("a new test comment")); + Thread.sleep(2000); } catch (InterruptedException e) { throw new RegistryException("Error adding comments to resource", e); } @@ -264,12 +265,18 @@ public void test4CustomQueryResultsOrderForComments() throws RegistryException { Resource r2 = registry.newResource(); r2.setContent("r2 content"); registry.put("/test/comments/r2", r2); - - registry.addComment("/test/comments/r2", new Comment("commentXX1 on this resource :)")); - registry.addComment("/test/comments/r2", new Comment("commentXX2 on this resource :)")); - registry.addComment("/test/comments/r2", new Comment("commentXX3 on this resource :)")); - registry.addComment("/test/comments/r2", new Comment("a new test comment")); - + try { + registry.addComment("/test/comments/r2", new Comment("commentXX1 on this resource :)")); + Thread.sleep(2000); + registry.addComment("/test/comments/r2", new Comment("commentXX2 on this resource :)")); + Thread.sleep(2000); + registry.addComment("/test/comments/r2", new Comment("commentXX3 on this resource :)")); + Thread.sleep(2000); + registry.addComment("/test/comments/r2", new Comment("a new test comment")); + Thread.sleep(2000); + } catch (InterruptedException e) { + throw new RegistryException("Sleep Thread Interrupted", e); + } comQuery = configSystemRegistry.newResource(); sql = "SELECT REG_COMMENT_ID FROM REG_COMMENT C, REG_RESOURCE_COMMENT RC " + "WHERE C.REG_COMMENT_TEXT LIKE ? AND C.REG_ID=RC.REG_COMMENT_ID " +