[jbpm-commits] JBoss JBPM SVN: r6175 - in jbpm3/branches/jbpm-3.2-soa/modules/core/src: test/java/org/jbpm/graph/log and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Feb 18 00:36:26 EST 2010


Author: alex.guizar at jboss.com
Date: 2010-02-18 00:36:25 -0500 (Thu, 18 Feb 2010)
New Revision: 6175

Modified:
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/LimitedStringType.java
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/LimitedTextType.java
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/graph/log/ActionLogDbTest.java
Log:
push limit param of ltdstring typedef to 65535 on mysql - make test aware of configured limit

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/LimitedStringType.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/LimitedStringType.java	2010-02-18 01:28:12 UTC (rev 6174)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/LimitedStringType.java	2010-02-18 05:36:25 UTC (rev 6175)
@@ -41,6 +41,10 @@
 
   private static final long serialVersionUID = 1L;
 
+  public int getLimit() {
+    return limit;
+  }
+
   public void set(PreparedStatement st, Object value, int index) throws SQLException {
     String text = (String) value;
     if (text.length() > limit) text = text.substring(0, limit);

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/LimitedTextType.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/LimitedTextType.java	2010-02-18 01:28:12 UTC (rev 6174)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/LimitedTextType.java	2010-02-18 05:36:25 UTC (rev 6175)
@@ -42,6 +42,10 @@
 
   private static final long serialVersionUID = 1L;
 
+  public int getLimit() {
+    return limit;
+  }
+
   public void set(PreparedStatement st, Object value, int index) throws SQLException {
     String text = (String) value;
     int length = text.length();

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/graph/log/ActionLogDbTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/graph/log/ActionLogDbTest.java	2010-02-18 01:28:12 UTC (rev 6174)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/graph/log/ActionLogDbTest.java	2010-02-18 05:36:25 UTC (rev 6175)
@@ -39,10 +39,14 @@
 
     ActionLog actionLog = new ActionLog(action);
     actionLog = (ActionLog) saveAndReload(actionLog);
-    assertNotNull(actionLog.getAction());
 
-    session.delete(actionLog);
-    session.delete(action);
+    try {
+      assertNotNull(actionLog.getAction());
+    }
+    finally {
+      session.delete(actionLog);
+      session.delete(action);
+    }
   }
 
   public void testActionExceptionLog() {
@@ -52,32 +56,43 @@
     actionLog.setException(exception);
     actionLog = (ActionLog) saveAndReload(actionLog);
 
-    String exceptionString = actionLog.getException();
-    assertNotNull("log exception is null", exceptionString);
+    try {
+      String fullStackTrace = getStackTrace(exception);
+      String savedStackTrace = actionLog.getException();
 
-    int expectedLength = 4000;
-    if (!isLimitEnforced()) {
-      StringWriter exceptionWriter = new StringWriter();
-      exception.printStackTrace(new PrintWriter(exceptionWriter));
-      expectedLength = exceptionWriter.getBuffer().length();
-      assert expectedLength > 4000 : expectedLength;
+      int expectedLength = Math.min(fullStackTrace.length(), getStackTraceLimit());
+      assertEquals(expectedLength, savedStackTrace.length());
+
+      assertEquals(fullStackTrace.substring(0, expectedLength), savedStackTrace);
     }
+    finally {
+      session.delete(actionLog);
+    }
+  }
 
-    int actualLength = exceptionString.length();
-    assert actualLength == expectedLength : actualLength;
-
-    session.delete(actionLog);
+  private String getStackTrace(RuntimeException exception) {
+    StringWriter exceptionWriter = new StringWriter();
+    exception.printStackTrace(new PrintWriter(exceptionWriter));
+    return exceptionWriter.toString();
   }
 
-  private boolean isLimitEnforced() {
-    Type propertyType = session.getSessionFactory()
-        .getClassMetadata(ActionLog.class)
-        .getPropertyType("exception");
-    return propertyType instanceof LimitedStringType || propertyType instanceof LimitedTextType;
+  private int getStackTraceLimit() {
+    Type type = session.getSessionFactory()
+      .getClassMetadata(ActionLog.class)
+      .getPropertyType("exception");
+    if (type instanceof LimitedStringType) {
+      LimitedStringType limitedType = (LimitedStringType) type;
+      return limitedType.getLimit();
+    }
+    if (type instanceof LimitedTextType) {
+      LimitedTextType limitedType = (LimitedTextType) type;
+      return limitedType.getLimit();
+    }
+    return Integer.MAX_VALUE;
   }
 
   private RuntimeException createExceptionChain(RuntimeException cause, int level) {
     return level == 100 ? cause : createExceptionChain(level % 10 == 0 ? new RuntimeException(
-        "level " + level, cause) : cause, level + 1);
+      "level " + level, cause) : cause, level + 1);
   }
 }



More information about the jbpm-commits mailing list