From do-not-reply at jboss.org Mon Apr 18 05:38:38 2011 Content-Type: multipart/mixed; boundary="===============7053981218806284809==" MIME-Version: 1.0 From: do-not-reply at jboss.org To: jbpm-commits at lists.jboss.org Subject: [jbpm-commits] JBoss JBPM SVN: r6915 - in jbpm3/tags/jbpm-3.2.10_SOA-3030/core/src: test/java/org/jbpm and 2 other directories. Date: Mon, 18 Apr 2011 05:38:38 -0400 Message-ID: <201104180938.p3I9ccnW012373@svn01.web.mwc.hst.phx2.redhat.com> --===============7053981218806284809== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: mputz Date: 2011-04-18 05:38:38 -0400 (Mon, 18 Apr 2011) New Revision: 6915 Added: jbpm3/tags/jbpm-3.2.10_SOA-3030/core/src/test/java/org/jbpm/jbpm3171/ jbpm3/tags/jbpm-3.2.10_SOA-3030/core/src/test/java/org/jbpm/jbpm3171/JBP= M3171Test.java Modified: jbpm3/tags/jbpm-3.2.10_SOA-3030/core/src/main/java/org/jbpm/graph/exe/Pr= ocessInstance.java jbpm3/tags/jbpm-3.2.10_SOA-3030/core/src/test/java/org/jbpm/db/DeletePro= cessInstanceDbTest.java Log: SOA-3030: Removed key from hashCode function, to ensure that the hashCode r= emains stable for persisted ProcessInstances Modified: jbpm3/tags/jbpm-3.2.10_SOA-3030/core/src/main/java/org/jbpm/graph= /exe/ProcessInstance.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- jbpm3/tags/jbpm-3.2.10_SOA-3030/core/src/main/java/org/jbpm/graph/exe/P= rocessInstance.java 2011-04-18 08:58:31 UTC (rev 6914) +++ jbpm3/tags/jbpm-3.2.10_SOA-3030/core/src/main/java/org/jbpm/graph/exe/P= rocessInstance.java 2011-04-18 09:38:38 UTC (rev 6915) @@ -502,14 +502,18 @@ && processDefinition.equals(other.getProcessDefinition()); } = + /** + * Computes the hash code for this process instance. Process instances w= ithout an id + * (not persisted to db) will return their {@linkplain System#identityHa= shCode(Object) identity + * hash code}. + */ public int hashCode() { - if (key =3D=3D null) return super.hashCode(); - - int result =3D 295436291 + key.hashCode(); - result =3D 1367411281 * result + processDefinition.hashCode(); - return result; + if (id !=3D 0) = + return (int) (id ^ (id >>> 32)); + else + return System.identityHashCode(this); } - + = public String toString() { return "ProcessInstance" + (key !=3D null ? '(' + key + ')' : id !=3D 0 ? "(" + id + ')' Modified: jbpm3/tags/jbpm-3.2.10_SOA-3030/core/src/test/java/org/jbpm/db/De= leteProcessInstanceDbTest.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- jbpm3/tags/jbpm-3.2.10_SOA-3030/core/src/test/java/org/jbpm/db/DeletePr= ocessInstanceDbTest.java 2011-04-18 08:58:31 UTC (rev 6914) +++ jbpm3/tags/jbpm-3.2.10_SOA-3030/core/src/test/java/org/jbpm/db/DeletePr= ocessInstanceDbTest.java 2011-04-18 09:38:38 UTC (rev 6915) @@ -112,7 +112,58 @@ newTransaction(); assertDeleted(processInstance); } + = + // Test related to JBPM-3171: if the ProcessInstance.hashCode function c= ontains the process instance key, + // the variable handling is broken, which results in a Integrity constra= int violation FK_TKVARMAP_CTXT table: JBPM_TOKENVARIABLEMAP + // at process instance deletion. + public void testDeleteProcessInstanceWithSubProcessInstanceAndVariableAn= dSetKey() { + ProcessDefinition buyCheese =3D ProcessDefinition.parseXmlString("" + + " " + + " " + + " " + + " " + + " " = + + " " + + " " + + " " + + " " + + " " = + + " " + + ""); + deployProcessDefinition(buyCheese); = + ProcessDefinition makeFondue =3D ProcessDefinition.parseXmlString("" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""); + deployProcessDefinition(makeFondue); + + ProcessInstance processInstance =3D jbpmContext.newProcessInstance("ma= ke fondue"); + processInstance.signal(); + + processInstance =3D saveAndReload(processInstance); + jbpmContext.getGraphSession().deleteProcessInstance(processInstance); + + newTransaction(); + assertDeleted(processInstance.getRootToken().getProcessInstance()); + assertDeleted(processInstance); + } + + = private void assertDeleted(ProcessInstance processInstance) { long processInstanceId =3D processInstance.getId(); assertNull("process instance not deleted: " + processInstanceId, Added: jbpm3/tags/jbpm-3.2.10_SOA-3030/core/src/test/java/org/jbpm/jbpm3171= /JBPM3171Test.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- jbpm3/tags/jbpm-3.2.10_SOA-3030/core/src/test/java/org/jbpm/jbpm3171/JB= PM3171Test.java (rev 0) +++ jbpm3/tags/jbpm-3.2.10_SOA-3030/core/src/test/java/org/jbpm/jbpm3171/JB= PM3171Test.java 2011-04-18 09:38:38 UTC (rev 6915) @@ -0,0 +1,86 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jbpm.jbpm3171; + +import java.util.Date; + +import org.jbpm.AbstractJbpmTestCase; +import org.jbpm.context.exe.ContextInstance; +import org.jbpm.graph.def.ProcessDefinition; +import org.jbpm.graph.exe.ProcessInstance; + +/** + * Test hashCode implementation of ProcessInstance and - as a result - + * correct variable handling + * = + * @see JBPM-3171 + * @author Martin Weiler + */ +public class JBPM3171Test extends AbstractJbpmTestCase { + + ProcessDefinition processDefinition; + + protected void setUp() throws Exception { + super.setUp(); + processDefinition =3D ProcessDefinition.createNewProcessDefinition(); = = + } + + // test normal variable handling + public void testVariableWithoutKey() { + ProcessInstance processInstance =3D new ProcessInstance(processDefinit= ion); + ContextInstance contextInstance =3D processInstance.getContextInstance= (); + contextInstance.setVariable("red", new String("hat")); + assertEquals("hat", contextInstance.getVariable("red")); + } + + // test variable handling when process instance has been created with a = key + public void testVariableWithKey() { + ProcessInstance processInstance =3D new ProcessInstance(processDefinit= ion, null, "key_at_instance_creation"); + ContextInstance contextInstance =3D processInstance.getContextInstance= (); = + contextInstance.setVariable("j", new String("boss")); + assertEquals("boss", contextInstance.getVariable("j")); + } = + + // test variable handling when setKey is called on the process instance = after creation = + public void testVariableAfterSettingKey() { + ProcessInstance processInstance =3D new ProcessInstance(processDefinit= ion); + ContextInstance contextInstance =3D processInstance.getContextInstance= (); = + contextInstance.setVariable("hiber", new String("nate")); + contextInstance.getProcessInstance().setKey("key_set_on_existing_insta= nce"); + assertEquals("nate", contextInstance.getVariable("hiber")); + } = + + // test if hashCode changes after setting a key on the process instance + public void testHashCodeAfterSettingKey() { = + ProcessInstance processInstance =3D new ProcessInstance(processDefinit= ion); + int hashCode =3D processInstance.hashCode(); + processInstance.setKey("key_set_on_existing_instance"); + assertEquals(hashCode, processInstance.hashCode()); + } + = + // basic ProcessInstance.hashCode test + public void testProcessInstanceHashCode() { + ProcessInstance processInstance1 =3D new ProcessInstance(processDefini= tion); + ProcessInstance processInstance2 =3D new ProcessInstance(processDefini= tion); + assertTrue(processInstance1.hashCode()!=3DprocessInstance2.hashCode())= ; = + } +} --===============7053981218806284809==--