Related to issue 38888: Failing SS Build
authorMartin Taal <martin.taal@openbravo.com>
Sun, 09 Dec 2018 22:42:08 +0100
changeset 7984 1556893328c3
parent 7983 494ce98ccc9a
child 7985 d63d59027567
Related to issue 38888: Failing SS Build
Solve sync test errors
src-test/org/openbravo/test/mobile/retail/multiserver/MultiserverUtils.java
src-test/org/openbravo/test/mobile/retail/multiserver/unittests/tests/dbsynch/SynchronizationChannels.java
--- a/src-test/org/openbravo/test/mobile/retail/multiserver/MultiserverUtils.java	Sun Dec 09 13:53:41 2018 +0100
+++ b/src-test/org/openbravo/test/mobile/retail/multiserver/MultiserverUtils.java	Sun Dec 09 22:42:08 2018 +0100
@@ -52,7 +52,7 @@
       .getPushPeriodMillis();
   private static final long routePeriodMillis = ConfigurationProperties.INSTANCE
       .getRoutePeriodMillis();
-  private static final long waitMillis = Math.max(10000,
+  public static final long waitMillis = Math.max(10000,
       (long) ((pushPeriodMillis + routePeriodMillis) * 1.2));
 
   public static void waitForCentralOutgoingSynced(ServerType storeServerType) {
@@ -157,6 +157,47 @@
     };
   }
 
+  public static void waitForSyncErrors(final long interval, final int tries,
+      final ServerType fromServerType, final ServerType toServerType) {
+
+    if (fromServerType == ServerType.UNKNOWN || fromServerType == ServerType.SINGLESERVER) {
+      return;
+    }
+
+    if (toServerType == ServerType.UNKNOWN || toServerType == ServerType.SINGLESERVER) {
+      return;
+    }
+
+    final String toServerKey = getServerKey(toServerType);
+
+    final String sqlOutgoing = "select COUNT(1) AS count from sym_outgoing_batch where node_id = '"
+        + toServerKey + "' and status = 'ER'";
+
+    new OBWait(interval, (int) tries) {
+
+      @Override
+      protected boolean until(final int currentIteration) {
+        final ArrayList<Boolean> hasError = new ArrayList<Boolean>();
+        hasError.add(false);
+        new DatabaseHelperSelect() {
+          @Override
+          protected void yieldResultSet(final ResultSet rs) throws SQLException {
+            final Long count = rs.getLong("count");
+            hasError.set(0, count > 0);
+          }
+        }.execute(sqlOutgoing, 1, fromServerType);
+        return hasError.get(0);
+      }
+
+      @Override
+      protected void timeout() {
+        throw new TimeoutException(String.format("The " + fromServerType.name()
+            + " has not got into error state after %s iterations and %s interval seconds", tries,
+            interval / 1000));
+      }
+    };
+  }
+
   private static void checkForBatchesInError(final ServerType fromServerType,
       final ServerType toServerType) {
 
--- a/src-test/org/openbravo/test/mobile/retail/multiserver/unittests/tests/dbsynch/SynchronizationChannels.java	Sun Dec 09 13:53:41 2018 +0100
+++ b/src-test/org/openbravo/test/mobile/retail/multiserver/unittests/tests/dbsynch/SynchronizationChannels.java	Sun Dec 09 22:42:08 2018 +0100
@@ -9,6 +9,7 @@
 import org.junit.FixMethodOrder;
 import org.junit.Test;
 import org.junit.runners.MethodSorters;
+import org.openbravo.test.mobile.core.utils.OBUtils;
 import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperInsertUpdateOrDelete;
 import org.openbravo.test.mobile.retail.mobilecore.utils.RetailUtils;
 import org.openbravo.test.mobile.retail.multiserver.MultiserverUtils;
@@ -53,11 +54,15 @@
   public void A_channelCanBeConfiguredToBeBlocking() {
     forceConflict();
 
+    OBUtils.pause(MultiserverUtils.waitMillis);
+
+    MultiserverUtils.waitForSyncErrors(1000, 30, ServerType.CENTRAL, ServerType.STORE1);
+
     final int nRecordsInserted = insertUnitOfMeasure(ServerType.CENTRAL,
         notDuplicatedUnitOfMeasureId, not_duplicated_uom_name);
     assertEquals(nRecordsInserted, 1);
 
-    MultiserverUtils.waitForSynchronization(ServerType.STORE1);
+    OBUtils.pause(MultiserverUtils.waitMillis);
 
     final boolean hasBeenSynchronized = checkUnitOfMeasureExists(ServerType.STORE1,
         notDuplicatedUnitOfMeasureId);
@@ -88,11 +93,16 @@
 
     forceConflict();
 
+    // extra pause for sym-ds
+    OBUtils.pause(40000);
+
     final int nRecordsInserted = insertUnitOfMeasure(ServerType.CENTRAL,
         notDuplicatedUnitOfMeasureId, not_duplicated_uom_name);
     assertEquals(nRecordsInserted, 1);
 
-    MultiserverUtils.waitForSynchronization(ServerType.STORE1);
+    OBUtils.pause(MultiserverUtils.waitMillis);
+    MultiserverUtils.waitForOutgoingSynced(MultiserverUtils.waitMillis, 10, ServerType.CENTRAL,
+        ServerType.STORE1);
 
     final boolean hasBeenSynchronized = checkUnitOfMeasureExists(ServerType.STORE1,
         notDuplicatedUnitOfMeasureId);
@@ -143,7 +153,6 @@
         duplicated_uom_name);
     insertUnitOfMeasure(ServerType.CENTRAL, duplicatedUnitOfMeasureId_CentralServer,
         duplicated_uom_name);
-    MultiserverUtils.waitForSynchronization(ServerType.STORE1);
   }
 
   private void resolveConflict() {
@@ -169,7 +178,8 @@
     final StringBuilder deleteUomQuery = new StringBuilder();
     deleteUomQuery.append("DELETE FROM c_uom ");
     deleteUomQuery.append("WHERE c_uom_id = '" + unitOfMeasureId + "'");
-    return new DatabaseHelperInsertUpdateOrDelete().execute(deleteUomQuery.toString(), 1, server);
+    return new DatabaseHelperInsertUpdateOrDelete().execute(deleteUomQuery.toString(),
+        DatabaseHelperInsertUpdateOrDelete.UNKNOWN_AFFECTED_ROWS, server);
   }
 
   private boolean checkUnitOfMeasureExists(final ServerType server, final String unitOfMeasureId) {
@@ -180,4 +190,5 @@
     final int count = new MultiserverDatabaseCount().execute(countUomQuery.toString(), server);
     return count > 0;
   }
+
 }