Author: jason.greene(a)jboss.com
Date: 2008-01-15 19:43:28 -0500 (Tue, 15 Jan 2008)
New Revision: 5140
Added:
pojo/tags/2.1.0.CR3/
pojo/tags/2.1.0.CR3/pom.xml
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/LocalConcurrentTest.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/LocalTxTest.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/NewReplicatedTest.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/NewReplicatedTxTest.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/ReplicatedCircularGraphTest.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/ReplicatedObjectGraphTest.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/ReplicatedTxTest.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/collection/ReplicatedSyncListTest.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/jmx/NotificationTest.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/memory/ReplicatedTest.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/optimistic/AbstractOptimisticTestCase.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/region/LocalConcurrentTest.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/region/LocalTest.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/rollback/ReplicatedTxTest.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/statetransfer/ReplicatedTest.java
Removed:
pojo/tags/2.1.0.CR3/pom.xml
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/LocalConcurrentTest.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/LocalTxTest.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/NewReplicatedTest.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/NewReplicatedTxTest.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/ReplicatedCircularGraphTest.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/ReplicatedObjectGraphTest.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/ReplicatedTxTest.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/TestingUtil.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/collection/ReplicatedSyncListTest.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/jmx/NotificationTest.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/memory/ReplicatedTest.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/optimistic/AbstractOptimisticTestCase.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/region/LocalConcurrentTest.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/region/LocalTest.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/rollback/ReplicatedTxTest.java
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/statetransfer/ReplicatedTest.java
Log:
Tag CR3
Copied: pojo/tags/2.1.0.CR3 (from rev 4776, pojo/branches/2.1)
Deleted: pojo/tags/2.1.0.CR3/pom.xml
===================================================================
--- pojo/branches/2.1/pom.xml 2007-11-26 18:16:13 UTC (rev 4776)
+++ pojo/tags/2.1.0.CR3/pom.xml 2008-01-16 00:43:28 UTC (rev 5140)
@@ -1,288 +0,0 @@
-<?xml version="1.0"?>
-<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>
- <properties>
- <jbosscache-pojo-version>2.1.0.CR2</jbosscache-pojo-version>
- <jbosscache-core-version>2.1.0.CR2</jbosscache-core-version>
- <jboss.aop.version>2.0.0.beta1</jboss.aop.version>
- </properties>
- <parent>
- <groupId>org.jboss.cache</groupId>
- <artifactId>jbosscache-common-parent</artifactId>
- <version>1.1</version>
- </parent>
- <groupId>org.jboss.cache</groupId>
- <artifactId>jbosscache-pojo</artifactId>
- <version>${jbosscache-pojo-version}</version>
- <name>JBoss Cache - POJO Edition</name>
- <description>JBoss Cache - POJO Edition</description>
- <packaging>jar</packaging>
- <dependencies>
- <dependency>
- <groupId>org.jboss.aop</groupId>
- <artifactId>jboss-aop</artifactId>
- <version>${jboss.aop.version}</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.cache</groupId>
- <artifactId>jbosscache-core</artifactId>
- <version>${jbosscache-core-version}</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.cache</groupId>
- <artifactId>jbosscache-core</artifactId>
- <version>${jbosscache-core-version}</version>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <!-- Hack AOP has broken deps -->
- <dependency>
- <groupId>org.jboss.microcontainer</groupId>
- <artifactId>jboss-container</artifactId>
- <version>2.0.0.Beta4</version>
- <scope>runtime</scope>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <version>2.2-beta-1</version>
- <executions>
- <execution>
- <id>assemble</id>
- <phase>install</phase>
- <goals>
- <goal>attached</goal>
- </goals>
- <configuration>
- <descriptors>
- <descriptor>assembly/bin.xml</descriptor>
- <descriptor>assembly/doc.xml</descriptor>
- <descriptor>assembly/all.xml</descriptor>
- </descriptors>
-
<finalName>${artifactId}-${jbosscache-pojo-version}</finalName>
- <outputDirectory>target/distribution</outputDirectory>
- <workDirectory>target/assembly/work</workDirectory>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.3</version>
- <configuration>
- <systemProperties>
- <property>
- <name>bind.address</name>
- <value>127.0.0.1</value>
- </property>
- <property>
- <name>java.net.preferIPv4Stack</name>
- <value>true</value>
- </property>
- <property>
- <name>jgroups.stack</name>
- <value>udp</value>
- </property>
- </systemProperties>
- <groups>functional</groups>
- <forkMode>always</forkMode>
-
<argLine>-Djboss.aop.path=${basedir}/src/main/resources/META-INF/pojocache-aop.xml
-javaagent:${settings.localRepository}/org/jboss/aop/jboss-aop/${jboss.aop.version}/jboss-aop-${jboss.aop.version}.jar</argLine>
- <!-- Warning, this does not work right on 2.4-SNAPSHOT, (see SUREFIRE-349)
-->
- <!-- This seems to fail in some cases on 2.3 as well, disable for now
-->
- <useSystemClassLoader>true</useSystemClassLoader>
- <redirectTestOutputToFile>false</redirectTestOutputToFile>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.jboss.maven.plugins</groupId>
- <artifactId>maven-jbossaop-plugin</artifactId>
- <version>2.0.0.beta1</version>
- <!-- HACK: AOP project and plugin has broken deps -->
- <dependencies>
- <dependency>
- <groupId>org.jboss.microcontainer</groupId>
- <artifactId>jboss-container</artifactId>
- <version>2.0.0.Beta4</version>
- </dependency>
- <dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- <version>1.0.4</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.cache</groupId>
- <artifactId>jbosscache-core</artifactId>
- <version>${jbosscache-core-version}</version>
- </dependency>
- </dependencies>
- <executions>
- <execution>
- <id>aopc</id>
- <phase>compile</phase>
- <goals>
- <goal>compile</goal>
- </goals>
- <configuration>
- <verbose>false</verbose>
- <aoppaths>
-
<aoppath>${basedir}/src/main/resources/META-INF/pojocache-aop.xml</aoppath>
- </aoppaths>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <!-- the docbook generation plugin for the user guide -->
- <plugin>
- <groupId>org.jboss.maven.plugins</groupId>
- <artifactId>maven-jdocbook-plugin</artifactId>
- <version>2.0.0</version>
- <extensions>true</extensions>
- <dependencies>
- <dependency>
- <groupId>org.jboss.cache</groupId>
- <artifactId>jbosscache-doc-xslt-support</artifactId>
- <version>1.0</version>
- </dependency>
- </dependencies>
- <executions>
-
- <!-- The User Guide-->
- <execution>
- <id>userguide_en</id>
- <phase>package</phase>
- <goals>
- <goal>resources</goal>
- <goal>generate</goal>
- </goals>
- <configuration>
- <sourceDocumentName>master.xml</sourceDocumentName>
-
<sourceDirectory>${basedir}/src/main/docbook/userguide/en</sourceDirectory>
- <imageResource>
- <directory>${basedir}/src/main/docbook/images</directory>
- </imageResource>
- <cssResource>
- <directory>${basedir}/src/main/docbook/css</directory>
- </cssResource>
-
<targetDirectory>${basedir}/target/docbook/userguide_en</targetDirectory>
- <formats>
- <format>
- <formatName>pdf</formatName>
-
<stylesheetResource>classpath:/standard/fopdf.xsl</stylesheetResource>
- <finalName>userguide_en.pdf</finalName>
- </format>
- <format>
- <formatName>html</formatName>
-
<stylesheetResource>classpath:/standard/html_chunk.xsl</stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- <format>
- <formatName>html_single</formatName>
-
<stylesheetResource>classpath:/standard/html.xsl</stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- </formats>
- <options>
- <xincludeSupported>false</xincludeSupported>
- </options>
- </configuration>
- </execution>
-
- <!-- The Tutorial -->
- <execution>
- <id>tutorial_en</id>
- <phase>package</phase>
- <goals>
- <goal>resources</goal>
- <goal>generate</goal>
- </goals>
- <configuration>
- <sourceDocumentName>master.xml</sourceDocumentName>
-
<sourceDirectory>${basedir}/src/main/docbook/tutorial/en</sourceDirectory>
- <imageResource>
- <directory>${basedir}/src/main/docbook/images</directory>
- </imageResource>
- <cssResource>
- <directory>${basedir}/src/main/docbook/css</directory>
- </cssResource>
-
<targetDirectory>${basedir}/target/docbook/tutorial_en</targetDirectory>
- <formats>
- <format>
- <formatName>pdf</formatName>
-
<stylesheetResource>classpath:/standard/fopdf.xsl</stylesheetResource>
- <finalName>tutorial_en.pdf</finalName>
- </format>
- <format>
- <formatName>html</formatName>
-
<stylesheetResource>classpath:/standard/html_chunk.xsl</stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- <format>
- <formatName>html_single</formatName>
-
<stylesheetResource>classpath:/standard/html.xsl</stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- </formats>
- <options>
- <xincludeSupported>false</xincludeSupported>
- </options>
- </configuration>
- </execution>
-
- <!-- the FAQs -->
- <execution>
- <id>faq_en</id>
- <phase>package</phase>
- <goals>
- <goal>resources</goal>
- <goal>generate</goal>
- </goals>
- <configuration>
- <sourceDocumentName>master.xml</sourceDocumentName>
-
<sourceDirectory>${basedir}/src/main/docbook/faq/en</sourceDirectory>
- <imageResource>
- <directory>${basedir}/src/main/docbook/images</directory>
- </imageResource>
- <cssResource>
- <directory>${basedir}/src/main/docbook/css</directory>
- </cssResource>
-
<targetDirectory>${basedir}/target/docbook/faq_en</targetDirectory>
- <formats>
- <format>
- <formatName>pdf</formatName>
-
<stylesheetResource>classpath:/standard/fopdf.xsl</stylesheetResource>
- <finalName>faq_en.pdf</finalName>
- </format>
- <format>
- <formatName>html</formatName>
-
<stylesheetResource>classpath:/standard/html_chunk.xsl</stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- <format>
- <formatName>html_single</formatName>
-
<stylesheetResource>classpath:/standard/html.xsl</stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- </formats>
- <options>
- <xincludeSupported>false</xincludeSupported>
- </options>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-
- <!-- basic JBoss repository so that the common parent POM in jbosscache-support can
be found -->
- <repositories>
- <repository>
- <id>repository.jboss.org</id>
- <
url>http://repository.jboss.org/maven2</url>
- </repository>
- </repositories>
-</project>
Copied: pojo/tags/2.1.0.CR3/pom.xml (from rev 5129, pojo/branches/2.1/pom.xml)
===================================================================
--- pojo/tags/2.1.0.CR3/pom.xml (rev 0)
+++ pojo/tags/2.1.0.CR3/pom.xml 2008-01-16 00:43:28 UTC (rev 5140)
@@ -0,0 +1,288 @@
+<?xml version="1.0"?>
+<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>
+ <properties>
+ <jbosscache-pojo-version>2.1.0.CR3</jbosscache-pojo-version>
+ <jbosscache-core-version>2.1.0.CR3</jbosscache-core-version>
+ <jboss.aop.version>2.0.0.CR3</jboss.aop.version>
+ </properties>
+ <parent>
+ <groupId>org.jboss.cache</groupId>
+ <artifactId>jbosscache-common-parent</artifactId>
+ <version>1.1</version>
+ </parent>
+ <groupId>org.jboss.cache</groupId>
+ <artifactId>jbosscache-pojo</artifactId>
+ <version>${jbosscache-pojo-version}</version>
+ <name>JBoss Cache - POJO Edition</name>
+ <description>JBoss Cache - POJO Edition</description>
+ <packaging>jar</packaging>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.aop</groupId>
+ <artifactId>jboss-aop</artifactId>
+ <version>${jboss.aop.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.cache</groupId>
+ <artifactId>jbosscache-core</artifactId>
+ <version>${jbosscache-core-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.cache</groupId>
+ <artifactId>jbosscache-core</artifactId>
+ <version>${jbosscache-core-version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <!-- Hack AOP has broken deps -->
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-container</artifactId>
+ <version>2.0.0.Beta4</version>
+ <scope>runtime</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.2-beta-1</version>
+ <executions>
+ <execution>
+ <id>assemble</id>
+ <phase>install</phase>
+ <goals>
+ <goal>attached</goal>
+ </goals>
+ <configuration>
+ <descriptors>
+ <descriptor>assembly/bin.xml</descriptor>
+ <descriptor>assembly/doc.xml</descriptor>
+ <descriptor>assembly/all.xml</descriptor>
+ </descriptors>
+
<finalName>${artifactId}-${jbosscache-pojo-version}</finalName>
+ <outputDirectory>target/distribution</outputDirectory>
+ <workDirectory>target/assembly/work</workDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.3</version>
+ <configuration>
+ <systemProperties>
+ <property>
+ <name>bind.address</name>
+ <value>127.0.0.1</value>
+ </property>
+ <property>
+ <name>java.net.preferIPv4Stack</name>
+ <value>true</value>
+ </property>
+ <property>
+ <name>jgroups.stack</name>
+ <value>udp</value>
+ </property>
+ </systemProperties>
+ <groups>functional</groups>
+ <forkMode>always</forkMode>
+
<argLine>-Djboss.aop.path=${basedir}/src/main/resources/META-INF/pojocache-aop.xml
-javaagent:${settings.localRepository}/org/jboss/aop/jboss-aop/${jboss.aop.version}/jboss-aop-${jboss.aop.version}.jar</argLine>
+ <!-- Warning, this does not work right on 2.4-SNAPSHOT, (see SUREFIRE-349)
-->
+ <!-- This seems to fail in some cases on 2.3 as well, disable for now
-->
+ <useSystemClassLoader>true</useSystemClassLoader>
+ <redirectTestOutputToFile>false</redirectTestOutputToFile>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.jboss.maven.plugins</groupId>
+ <artifactId>maven-jbossaop-plugin</artifactId>
+ <version>2.0.0.beta1</version>
+ <!-- HACK: AOP project and plugin has broken deps -->
+ <dependencies>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.0.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.cache</groupId>
+ <artifactId>jbosscache-core</artifactId>
+ <version>${jbosscache-core-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.aop</groupId>
+ <artifactId>jboss-aop</artifactId>
+ <version>${jboss.aop.version}</version>
+ </dependency>
+ </dependencies>
+ <executions>
+ <execution>
+ <id>aopc</id>
+ <phase>compile</phase>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ <configuration>
+ <verbose>false</verbose>
+ <aoppaths>
+
<aoppath>${basedir}/src/main/resources/META-INF/pojocache-aop.xml</aoppath>
+ </aoppaths>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <!-- the docbook generation plugin for the user guide -->
+ <plugin>
+ <groupId>org.jboss.maven.plugins</groupId>
+ <artifactId>maven-jdocbook-plugin</artifactId>
+ <version>2.0.0</version>
+ <extensions>true</extensions>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.cache</groupId>
+ <artifactId>jbosscache-doc-xslt-support</artifactId>
+ <version>1.0</version>
+ </dependency>
+ </dependencies>
+ <executions>
+
+ <!-- The User Guide-->
+ <execution>
+ <id>userguide_en</id>
+ <phase>package</phase>
+ <goals>
+ <goal>resources</goal>
+ <goal>generate</goal>
+ </goals>
+ <configuration>
+ <sourceDocumentName>master.xml</sourceDocumentName>
+
<sourceDirectory>${basedir}/src/main/docbook/userguide/en</sourceDirectory>
+ <imageResource>
+ <directory>${basedir}/src/main/docbook/images</directory>
+ </imageResource>
+ <cssResource>
+ <directory>${basedir}/src/main/docbook/css</directory>
+ </cssResource>
+
<targetDirectory>${basedir}/target/docbook/userguide_en</targetDirectory>
+ <formats>
+ <format>
+ <formatName>pdf</formatName>
+
<stylesheetResource>classpath:/standard/fopdf.xsl</stylesheetResource>
+ <finalName>userguide_en.pdf</finalName>
+ </format>
+ <format>
+ <formatName>html</formatName>
+
<stylesheetResource>classpath:/standard/html_chunk.xsl</stylesheetResource>
+ <finalName>index.html</finalName>
+ </format>
+ <format>
+ <formatName>html_single</formatName>
+
<stylesheetResource>classpath:/standard/html.xsl</stylesheetResource>
+ <finalName>index.html</finalName>
+ </format>
+ </formats>
+ <options>
+ <xincludeSupported>false</xincludeSupported>
+ </options>
+ </configuration>
+ </execution>
+
+ <!-- The Tutorial -->
+ <execution>
+ <id>tutorial_en</id>
+ <phase>package</phase>
+ <goals>
+ <goal>resources</goal>
+ <goal>generate</goal>
+ </goals>
+ <configuration>
+ <sourceDocumentName>master.xml</sourceDocumentName>
+
<sourceDirectory>${basedir}/src/main/docbook/tutorial/en</sourceDirectory>
+ <imageResource>
+ <directory>${basedir}/src/main/docbook/images</directory>
+ </imageResource>
+ <cssResource>
+ <directory>${basedir}/src/main/docbook/css</directory>
+ </cssResource>
+
<targetDirectory>${basedir}/target/docbook/tutorial_en</targetDirectory>
+ <formats>
+ <format>
+ <formatName>pdf</formatName>
+
<stylesheetResource>classpath:/standard/fopdf.xsl</stylesheetResource>
+ <finalName>tutorial_en.pdf</finalName>
+ </format>
+ <format>
+ <formatName>html</formatName>
+
<stylesheetResource>classpath:/standard/html_chunk.xsl</stylesheetResource>
+ <finalName>index.html</finalName>
+ </format>
+ <format>
+ <formatName>html_single</formatName>
+
<stylesheetResource>classpath:/standard/html.xsl</stylesheetResource>
+ <finalName>index.html</finalName>
+ </format>
+ </formats>
+ <options>
+ <xincludeSupported>false</xincludeSupported>
+ </options>
+ </configuration>
+ </execution>
+
+ <!-- the FAQs -->
+ <execution>
+ <id>faq_en</id>
+ <phase>package</phase>
+ <goals>
+ <goal>resources</goal>
+ <goal>generate</goal>
+ </goals>
+ <configuration>
+ <sourceDocumentName>master.xml</sourceDocumentName>
+
<sourceDirectory>${basedir}/src/main/docbook/faq/en</sourceDirectory>
+ <imageResource>
+ <directory>${basedir}/src/main/docbook/images</directory>
+ </imageResource>
+ <cssResource>
+ <directory>${basedir}/src/main/docbook/css</directory>
+ </cssResource>
+
<targetDirectory>${basedir}/target/docbook/faq_en</targetDirectory>
+ <formats>
+ <format>
+ <formatName>pdf</formatName>
+
<stylesheetResource>classpath:/standard/fopdf.xsl</stylesheetResource>
+ <finalName>faq_en.pdf</finalName>
+ </format>
+ <format>
+ <formatName>html</formatName>
+
<stylesheetResource>classpath:/standard/html_chunk.xsl</stylesheetResource>
+ <finalName>index.html</finalName>
+ </format>
+ <format>
+ <formatName>html_single</formatName>
+
<stylesheetResource>classpath:/standard/html.xsl</stylesheetResource>
+ <finalName>index.html</finalName>
+ </format>
+ </formats>
+ <options>
+ <xincludeSupported>false</xincludeSupported>
+ </options>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <!-- basic JBoss repository so that the common parent POM in jbosscache-support can
be found -->
+ <repositories>
+ <repository>
+ <id>repository.jboss.org</id>
+ <
url>http://repository.jboss.org/maven2</url>
+ </repository>
+ </repositories>
+</project>
Deleted: pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/LocalConcurrentTest.java
===================================================================
---
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/LocalConcurrentTest.java 2007-11-26
18:16:13 UTC (rev 4776)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/LocalConcurrentTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -1,269 +0,0 @@
-/*
- *
- * JBoss, the OpenSource J2EE webOS
- *
- * Distributable under LGPL license.
- * See terms of license at
gnu.org.
- */
-
-package org.jboss.cache.pojo;
-
-import java.util.ArrayList;
-import java.util.Properties;
-import java.util.Random;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.transaction.UserTransaction;
-
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.lock.UpgradeException;
-import org.jboss.cache.pojo.test.Address;
-import org.jboss.cache.pojo.test.Person;
-import org.jboss.cache.transaction.DummyTransactionManager;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-
-/**
- * Local concurrent test for PojoCache. Test attach and detach under load
- * and concurrency.
- *
- * @version $Revision$
- * @author<a href="mailto:bwang@jboss.org">Ben Wang</a> December
2004
- */
-@Test(groups = {"functional"}, enabled = false)
-public class LocalConcurrentTest
-{
- static PojoCache cache_;
- Configuration.CacheMode cachingMode_ = Configuration.CacheMode.LOCAL;
- Properties p_;
- String oldFactory_ = null;
- final String FACTORY = "org.jboss.cache.transaction.DummyContextFactory";
- static ArrayList<String> nodeList_;
- static final int depth_ = 2;
- static final int children_ = 2;
- static final int MAX_LOOP = 100;
- static final int SLEEP_TIME = 50;
- static Exception thread_ex = null;
- UserTransaction tx_ = null;
-
- @BeforeMethod(alwaysRun = true)
- public void setUp() throws Exception
- {
- oldFactory_ = System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
- System.setProperty(Context.INITIAL_CONTEXT_FACTORY, FACTORY);
- DummyTransactionManager.getInstance();
- if (p_ == null)
- {
- p_ = new Properties();
- p_.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.cache.transaction.DummyContextFactory");
- }
-
- tx_ = (UserTransaction) new
InitialContext(p_).lookup("UserTransaction");
-
- initCaches(Configuration.CacheMode.LOCAL);
- nodeList_ = nodeGen(depth_, children_);
-
- log("LocalConcurrentTestCase: cacheMode=TRANSIENT, one cache");
- }
-
- @AfterMethod(alwaysRun = true)
- public void tearDown() throws Exception
- {
- thread_ex = null;
- DummyTransactionManager.destroy();
- destroyCaches();
-
- if (oldFactory_ != null)
- {
- System.setProperty(Context.INITIAL_CONTEXT_FACTORY, oldFactory_);
- oldFactory_ = null;
- }
-
- }
-
- void initCaches(Configuration.CacheMode caching_mode) throws Exception
- {
- cachingMode_ = caching_mode;
- boolean toStart = false;
- cache_ = PojoCacheFactory.createCache("META-INF/local-service.xml",
toStart);
- cache_.start();
- }
-
- void destroyCaches() throws Exception
- {
- cache_.stop();
- cache_ = null;
- }
-
- public void testAll_RWLock() throws Exception
- {
- try
- {
- all();
- }
- catch (UpgradeException ue)
- {
- log("Upgrade exception. Can ingore for repeatable read. " + ue);
- }
- catch (Exception ex)
- {
- log("Exception: " + ex);
- throw ex;
- }
- }
-
- private void all() throws Exception
- {
- RunThread t1 = new RunThread(1);
- RunThread t2 = new RunThread(2);
- RunThread t3 = new RunThread(3);
- RunThread t4 = new RunThread(4);
-
- t1.start();
- TestingUtil.sleepThread(100);
- t2.start();
- TestingUtil.sleepThread(100);
- t3.start();
- TestingUtil.sleepThread(100);
- t4.start();
-
- t1.join(60000);// wait for 20 secs
- t2.join(60000);// wait for 20 secs
- t3.join(60000);// wait for 20 secs
- t4.join(60000);// wait for 20 secs
-
- if (thread_ex != null)
- {
- throw thread_ex;
- }
- }
-
- class RunThread extends Thread
- {
- final int seed_;
- Random random_;
- Person person_;
-
- public RunThread(int seed)
- {
- seed_ = seed;
- random_ = new Random(seed);
- }
-
- private void createPerson()
- {
- person_ = new Person();
- person_.setName("Ben");
- person_.setAge(18);
- ArrayList<String> lang = new ArrayList<String>();
- lang.add("English");
- lang.add("French");
- lang.add("Mandarin");
- person_.setLanguages(lang);
- Address addr = new Address();
- addr.setZip(95123);
- addr.setStreet("Almeria");
- addr.setCity("San Jose");
- person_.setAddress(addr);
- }
-
- public void run()
- {
- try
- {
- _run();
- }
- catch (Exception e)
- {
- thread_ex = e;
- }
- }
-
- /**
- */
- public void _run() throws Exception
- {
- for (int loop = 0; loop < MAX_LOOP; loop++)
- {
- createPerson();// create a new person instance every loop.
- TestingUtil.sleepThread(random_.nextInt(50));
- op1();
- }
- }
-
- // Operation 1
- private void op1()
- {
- int i = random_.nextInt(nodeList_.size() - 1);
- if (i == 0) return;// it is meaningless to test root
- String node = nodeList_.get(i) + "/aop";
- cache_.attach(node, person_);
- TestingUtil.sleepThread(random_.nextInt(SLEEP_TIME));// sleep for max 200
millis
- TestingUtil.sleepThread(random_.nextInt(SLEEP_TIME));// sleep for max 200
millis
- cache_.detach(node);
- }
- }
-
- /**
- * Generate the tree nodes quasi-exponentially. I.e., depth is the level
- * of the hierarchy and children is the number of children under each node.
- * This strucutre is used to add, get, and remove for each node.
- */
- private ArrayList<String> nodeGen(int depth, int children)
- {
- ArrayList<String> strList = new ArrayList<String>();
- ArrayList<String> oldList = new ArrayList<String>();
- ArrayList<String> newList = new ArrayList<String>();
-
- // Skip root node
- oldList.add("/");
- newList.add("/");
- strList.add("/");
-
- while (depth > 0)
- {
- // Trying to produce node name at this depth.
- newList = new ArrayList<String>();
- for (int i = 0; i < oldList.size(); i++)
- {
- for (int j = 0; j < children; j++)
- {
- String tmp = oldList.get(i);
- tmp += Integer.toString(j);
- if (depth != 1)
- {
- tmp += "/";
- }
-
- newList.add(tmp);
- }
- }
- strList.addAll(newList);
- oldList = newList;
- depth--;
- }
-
- // let's prune out root node
- for (int i = 0; i < strList.size(); i++)
- {
- if (strList.get(i).equals("/"))
- {
- strList.remove(i);
- break;
- }
- }
- log("Nodes generated: " + strList.size());
- return strList;
- }
-
-
- private static void log(String str)
- {
- System.out.println("Thread: " + Thread.currentThread() + ": " +
str);
- // System.out.println(str);
- }
-
-}
Copied: pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/LocalConcurrentTest.java
(from rev 5129,
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/LocalConcurrentTest.java)
===================================================================
--- pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/LocalConcurrentTest.java
(rev 0)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/LocalConcurrentTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -0,0 +1,270 @@
+/*
+ *
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at
gnu.org.
+ */
+
+package org.jboss.cache.pojo;
+
+import java.util.ArrayList;
+import java.util.Properties;
+import java.util.Random;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.transaction.UserTransaction;
+
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.lock.UpgradeException;
+import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.pojo.test.Address;
+import org.jboss.cache.pojo.test.Person;
+import org.jboss.cache.transaction.DummyTransactionManager;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+
+/**
+ * Local concurrent test for PojoCache. Test attach and detach under load
+ * and concurrency.
+ *
+ * @version $Revision$
+ * @author<a href="mailto:bwang@jboss.org">Ben Wang</a> December
2004
+ */
+@Test(groups = {"functional"}, enabled = false)
+public class LocalConcurrentTest
+{
+ static PojoCache cache_;
+ Configuration.CacheMode cachingMode_ = Configuration.CacheMode.LOCAL;
+ Properties p_;
+ String oldFactory_ = null;
+ final String FACTORY = "org.jboss.cache.transaction.DummyContextFactory";
+ static ArrayList<String> nodeList_;
+ static final int depth_ = 2;
+ static final int children_ = 2;
+ static final int MAX_LOOP = 100;
+ static final int SLEEP_TIME = 50;
+ static Exception thread_ex = null;
+ UserTransaction tx_ = null;
+
+ @BeforeMethod(alwaysRun = true)
+ public void setUp() throws Exception
+ {
+ oldFactory_ = System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
+ System.setProperty(Context.INITIAL_CONTEXT_FACTORY, FACTORY);
+ DummyTransactionManager.getInstance();
+ if (p_ == null)
+ {
+ p_ = new Properties();
+ p_.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.cache.transaction.DummyContextFactory");
+ }
+
+ tx_ = (UserTransaction) new
InitialContext(p_).lookup("UserTransaction");
+
+ initCaches(Configuration.CacheMode.LOCAL);
+ nodeList_ = nodeGen(depth_, children_);
+
+ log("LocalConcurrentTestCase: cacheMode=TRANSIENT, one cache");
+ }
+
+ @AfterMethod(alwaysRun = true)
+ public void tearDown() throws Exception
+ {
+ thread_ex = null;
+ DummyTransactionManager.destroy();
+ destroyCaches();
+
+ if (oldFactory_ != null)
+ {
+ System.setProperty(Context.INITIAL_CONTEXT_FACTORY, oldFactory_);
+ oldFactory_ = null;
+ }
+
+ }
+
+ void initCaches(Configuration.CacheMode caching_mode) throws Exception
+ {
+ cachingMode_ = caching_mode;
+ boolean toStart = false;
+ cache_ = PojoCacheFactory.createCache("META-INF/local-service.xml",
toStart);
+ cache_.start();
+ }
+
+ void destroyCaches() throws Exception
+ {
+ cache_.stop();
+ cache_ = null;
+ }
+
+ public void testAll_RWLock() throws Exception
+ {
+ try
+ {
+ all();
+ }
+ catch (UpgradeException ue)
+ {
+ log("Upgrade exception. Can ingore for repeatable read. " + ue);
+ }
+ catch (Exception ex)
+ {
+ log("Exception: " + ex);
+ throw ex;
+ }
+ }
+
+ private void all() throws Exception
+ {
+ RunThread t1 = new RunThread(1);
+ RunThread t2 = new RunThread(2);
+ RunThread t3 = new RunThread(3);
+ RunThread t4 = new RunThread(4);
+
+ t1.start();
+ TestingUtil.sleepThread(100);
+ t2.start();
+ TestingUtil.sleepThread(100);
+ t3.start();
+ TestingUtil.sleepThread(100);
+ t4.start();
+
+ t1.join(60000);// wait for 20 secs
+ t2.join(60000);// wait for 20 secs
+ t3.join(60000);// wait for 20 secs
+ t4.join(60000);// wait for 20 secs
+
+ if (thread_ex != null)
+ {
+ throw thread_ex;
+ }
+ }
+
+ class RunThread extends Thread
+ {
+ final int seed_;
+ Random random_;
+ Person person_;
+
+ public RunThread(int seed)
+ {
+ seed_ = seed;
+ random_ = new Random(seed);
+ }
+
+ private void createPerson()
+ {
+ person_ = new Person();
+ person_.setName("Ben");
+ person_.setAge(18);
+ ArrayList<String> lang = new ArrayList<String>();
+ lang.add("English");
+ lang.add("French");
+ lang.add("Mandarin");
+ person_.setLanguages(lang);
+ Address addr = new Address();
+ addr.setZip(95123);
+ addr.setStreet("Almeria");
+ addr.setCity("San Jose");
+ person_.setAddress(addr);
+ }
+
+ public void run()
+ {
+ try
+ {
+ _run();
+ }
+ catch (Exception e)
+ {
+ thread_ex = e;
+ }
+ }
+
+ /**
+ */
+ public void _run() throws Exception
+ {
+ for (int loop = 0; loop < MAX_LOOP; loop++)
+ {
+ createPerson();// create a new person instance every loop.
+ TestingUtil.sleepThread(random_.nextInt(50));
+ op1();
+ }
+ }
+
+ // Operation 1
+ private void op1()
+ {
+ int i = random_.nextInt(nodeList_.size() - 1);
+ if (i == 0) return;// it is meaningless to test root
+ String node = nodeList_.get(i) + "/aop";
+ cache_.attach(node, person_);
+ TestingUtil.sleepThread(random_.nextInt(SLEEP_TIME));// sleep for max 200
millis
+ TestingUtil.sleepThread(random_.nextInt(SLEEP_TIME));// sleep for max 200
millis
+ cache_.detach(node);
+ }
+ }
+
+ /**
+ * Generate the tree nodes quasi-exponentially. I.e., depth is the level
+ * of the hierarchy and children is the number of children under each node.
+ * This strucutre is used to add, get, and remove for each node.
+ */
+ private ArrayList<String> nodeGen(int depth, int children)
+ {
+ ArrayList<String> strList = new ArrayList<String>();
+ ArrayList<String> oldList = new ArrayList<String>();
+ ArrayList<String> newList = new ArrayList<String>();
+
+ // Skip root node
+ oldList.add("/");
+ newList.add("/");
+ strList.add("/");
+
+ while (depth > 0)
+ {
+ // Trying to produce node name at this depth.
+ newList = new ArrayList<String>();
+ for (int i = 0; i < oldList.size(); i++)
+ {
+ for (int j = 0; j < children; j++)
+ {
+ String tmp = oldList.get(i);
+ tmp += Integer.toString(j);
+ if (depth != 1)
+ {
+ tmp += "/";
+ }
+
+ newList.add(tmp);
+ }
+ }
+ strList.addAll(newList);
+ oldList = newList;
+ depth--;
+ }
+
+ // let's prune out root node
+ for (int i = 0; i < strList.size(); i++)
+ {
+ if (strList.get(i).equals("/"))
+ {
+ strList.remove(i);
+ break;
+ }
+ }
+ log("Nodes generated: " + strList.size());
+ return strList;
+ }
+
+
+ private static void log(String str)
+ {
+ System.out.println("Thread: " + Thread.currentThread() + ": " +
str);
+ // System.out.println(str);
+ }
+
+}
Deleted: pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/LocalTxTest.java
===================================================================
--- pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/LocalTxTest.java 2007-11-26
18:16:13 UTC (rev 4776)
+++ pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/LocalTxTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -1,441 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at
gnu.org.
- */
-
-package org.jboss.cache.pojo;
-
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.fail;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.transaction.NotSupportedException;
-import javax.transaction.RollbackException;
-import javax.transaction.SystemException;
-import javax.transaction.UserTransaction;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.pojo.test.Address;
-import org.jboss.cache.pojo.test.Person;
-import org.jboss.cache.transaction.DummyTransactionManager;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-/**
- */
-
-@Test(groups = {"functional"})
-public class LocalTxTest
-{
- Log log = LogFactory.getLog(LocalTxTest.class);
- PojoCache cache;
- final String FACTORY = "org.jboss.cache.transaction.DummyContextFactory";
- DummyTransactionManager tx_mgr;
- Throwable t1_ex, t2_ex;
- long start = 0;
-
-
-
- @BeforeMethod(alwaysRun = true)
- protected void setUp() throws Exception
- {
- log.info("setUp() ....");
- String configFile = "META-INF/local-service.xml";
- boolean toStart = false;
- cache = PojoCacheFactory.createCache(configFile, toStart);
- cache.start();
-
- System.setProperty(Context.INITIAL_CONTEXT_FACTORY, FACTORY);
-
- tx_mgr = DummyTransactionManager.getInstance();
- t1_ex = t2_ex = null;
- }
-
- @AfterMethod(alwaysRun = true)
- protected void tearDown() throws Exception
- {
- cache.stop();
-
- DummyTransactionManager.destroy();
- }
-
-// public void testDummy() {}
-
- UserTransaction getTransaction() throws SystemException, NotSupportedException,
NamingException
- {
- Properties prop = new Properties();
- prop.put(Context.INITIAL_CONTEXT_FACTORY,
- "org.jboss.cache.transaction.DummyContextFactory");
- return (UserTransaction) new
InitialContext(prop).lookup("UserTransaction");
- }
-
- private Person createPerson(String id, String name, int age)
- {
- Person p = new Person();
- p.setName(name);
- p.setAge(age);
- cache.attach(id, p);
- return p;
- }
-
- public void testSimple() throws Exception
- {
- log.info("testSimple() ....");
- UserTransaction tx = getTransaction();
- tx.begin();
- Person p = createPerson("/person/test1", "Harald Gliebe", 32);
- tx.commit();
- tx.begin();
- p.setName("Benoit");
- tx.commit();
- Person p1 = (Person) cache.find("/person/test1");
- assertEquals("Benoit", p.getName());
- assertEquals("Benoit", p1.getName());
- tx.begin();
- p1.setAge(61);
- tx.commit();
- assertEquals(61, p.getAge());
- assertEquals(61, p1.getAge());
- }
-
- public void testModification() throws Exception
- {
- UserTransaction tx = getTransaction();
- tx.begin();
- Person p = createPerson("/person/test2", "Harald", 32);
- p.setName("Harald Gliebe");
- tx.commit();
- Person p1 = (Person) cache.find("/person/test2");
- tx.begin();
- p1.setName("Benoit");
- tx.commit();
- assertEquals(p.getName(), "Benoit");
- assertEquals(p1.getName(), "Benoit");
- tx.begin();
- p1.setName("Harald");
- tx.rollback();
- assertEquals(p.getName(), "Benoit");
- assertEquals(p1.getName(), "Benoit");
- }
-
- public void testConcurrentSimplePuts() throws Exception
- {
- Thread t1 = new Thread("t1")
- {
- public void run()
- {
- try
- {
- Person p = (Person) cache.find("/person/test6");
- Address addr = new Address();
- addr.setCity("San Jose");
- UserTransaction tx = getTransaction();
- tx.begin();
- // Note that this will create a write lock on p (on the JBossInternal
node)
- p.setAddress(addr);
- TestingUtil.sleepThread(17000);
- tx.commit();
- }
- catch (RollbackException rollback)
- {
- ;
- }
- catch (Exception ex)
- {
- t1_ex = ex;
- }
- }
- };
-
- Thread t2 = new Thread("t2")
- {
- public void run()
- {
- UserTransaction tx = null;
- try
- {
- TestingUtil.sleepThread(1000); // give Thread1 time to createPerson
- Person p = (Person) cache.find("/person/test6");
- Address addr = new Address();
- addr.setCity("Santa Clara");
- tx = getTransaction();
- tx.begin();
- p.setAddress(addr);
- tx.commit();
- }
- catch (RollbackException rollback)
- {
- ;
- }
- catch (org.jboss.cache.pojo.PojoCacheException tex)
- {
- // This will be a timeout exception. OK.
- }
- catch (Exception ex)
- {
-// t2_ex = ex;
- if (tx != null)
- {
- try
- {
- tx.rollback();
- }
- catch (SystemException e)
- {
- e.printStackTrace();
- t2_ex = e;
- }
- }
- t2_ex = ex;
- ex.printStackTrace();
- }
- }
- };
-
- Person p = createPerson("/person/test6", "p6", 50);
-
- t1.start();
- t2.start();
-
- t1.join();
- t2.join();
-
- // t2 should rollback due to timeout while t2 should succeed
- if (t2_ex != null)
- fail("Thread1 failed: " + t2_ex);
- if (t1_ex != null)
- fail("Thread2 failed: " + t1_ex);
-
- assertEquals("City ", "San Jose", p.getAddress().getCity());
- }
-
- public void testConcurrentPuts() throws Exception
- {
- Thread t1 = new Thread("t1")
- {
- public void run()
- {
- try
- {
- List<String> lang = ((Person)
cache.find("/person/test6")).getLanguages();
- UserTransaction tx = getTransaction();
- tx.begin();
- lang.add("German");
- TestingUtil.sleepThread(17000);
- tx.commit();
- }
- catch (RollbackException rollback)
- {
- ;
- }
- catch (Exception ex)
- {
- t1_ex = ex;
- }
- }
- };
-
- Thread t2 = new Thread("t2")
- {
- public void run()
- {
- UserTransaction tx = null;
- try
- {
- TestingUtil.sleepThread(1000); // give Thread1 time to createPerson
- List<String> lang = ((Person)
cache.find("/person/test6")).getLanguages();
- tx = getTransaction();
- tx.begin();
- lang.add("English");
- tx.commit();
- }
- catch (RollbackException rollback)
- {
- ;
- }
- catch (org.jboss.cache.lock.TimeoutException tex)
- {
- //
- }
- catch (Exception ex)
- {
- if (tx != null)
- {
- try
- {
- tx.rollback();
- }
- catch (SystemException e)
- {
- e.printStackTrace();
- t2_ex = e;
- }
- }
- t2_ex = ex;
- ex.printStackTrace();
- }
- }
- };
-
- Person p = createPerson("/person/test6", "p6", 50);
- List<String> lang = new ArrayList<String>();
- lang.add("German");
- p.setLanguages(lang);
-
- t1.start();
- t2.start();
-
- t1.join();
- t2.join();
-
- // t2 should rollback due to timeout while t2 should succeed
- if (t2_ex != null)
- fail("Thread1 failed: " + t2_ex);
- if (t1_ex != null)
- fail("Thread2 failed: " + t1_ex);
-
- int size = ((Person) cache.find("/person/test6")).getLanguages().size();
- assertEquals("number of languages ",
- 2, size);
- }
-
- public void testConcurrentPutsNoWait() throws Exception
- {
- Thread t1 = new Thread("t1")
- {
- UserTransaction tx;
-
- public void run()
- {
- try
- {
- for (int i = 0; i < 100; i++)
- {
- String id = "/p1/test7";
- Person p = createPerson(id, "p6", 50);
- cache.detach(id);
- p = createPerson(id, "p6", 51);
- List<String> lang = new ArrayList<String>();
- tx = getTransaction();
- tx.begin();
- lang.add("German");
- lang.add("English");
- try
- {
- p.setLanguages(lang);
- }
- catch (PojoCacheException ex)
- {
- ex.printStackTrace();
- }
- tx.commit();
- TestingUtil.sleepThread(20); // give Thread1 time to createPerson
- }
- }
- catch (RollbackException rollback)
- {
- rollback.printStackTrace();
- }
- catch (PojoCacheException pe)
- {
- pe.printStackTrace();
- }
- catch (Exception ex)
- {
- t1_ex = ex;
- }
- }
- };
-
- Thread t2 = new Thread("t2")
- {
- UserTransaction tx;
-
- public void run()
- {
- try
- {
- for (int i = 0; i < 100; i++)
- {
- String id = "/p1/test8";
- Person p = createPerson(id, "p6", 50);
- cache.detach(id);
- p = createPerson(id, "p6", 51);
- List<String> lang = new ArrayList<String>();
- tx = getTransaction();
- tx.begin();
- lang.add("German");
- lang.add("English");
- try
- {
- p.setLanguages(lang);
- }
- catch (PojoCacheException ex)
- {
- ex.printStackTrace();
- }
- tx.commit();
- TestingUtil.sleepThread(20); // give Thread1 time to createPerson
- }
- }
- catch (RollbackException rollback)
- {
- rollback.printStackTrace();
- }
- catch (PojoCacheException pe)
- {
- pe.printStackTrace();
- }
- catch (Exception ex)
- {
- t2_ex = ex;
- ex.printStackTrace();
- }
- }
- };
-
- createPerson("/p1/test6", "p6", 50);
- createPerson("/p2/test6", "p6", 50);
-
- t1.start();
- t2.start();
-
- t1.join();
- t2.join();
-
- // t2 should rollback due to timeout while t2 should succeed
- if (t2_ex != null)
- fail("Thread1 failed: " + t2_ex);
- if (t1_ex != null)
- fail("Thread2 failed: " + t1_ex);
-
-// int size = ((Person) cache.find("/p1/test7")).getLanguages().size();
-// assertEquals("number of languages ",
-// 2, size);
- }
-
- void log(String s)
- {
- long now;
- if (start == 0)
- start = System.currentTimeMillis();
- now = System.currentTimeMillis();
-
- System.out.println("[" + Thread.currentThread().getName() + "]
[" + (now - start) + "] " + s);
- }
-
-
-
-
-
-}
Copied: pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/LocalTxTest.java (from rev
5129, pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/LocalTxTest.java)
===================================================================
--- pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/LocalTxTest.java
(rev 0)
+++ pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/LocalTxTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -0,0 +1,442 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at
gnu.org.
+ */
+
+package org.jboss.cache.pojo;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+import javax.transaction.UserTransaction;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.pojo.test.Address;
+import org.jboss.cache.pojo.test.Person;
+import org.jboss.cache.transaction.DummyTransactionManager;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ */
+
+@Test(groups = {"functional"})
+public class LocalTxTest
+{
+ Log log = LogFactory.getLog(LocalTxTest.class);
+ PojoCache cache;
+ final String FACTORY = "org.jboss.cache.transaction.DummyContextFactory";
+ DummyTransactionManager tx_mgr;
+ Throwable t1_ex, t2_ex;
+ long start = 0;
+
+
+
+ @BeforeMethod(alwaysRun = true)
+ protected void setUp() throws Exception
+ {
+ log.info("setUp() ....");
+ String configFile = "META-INF/local-service.xml";
+ boolean toStart = false;
+ cache = PojoCacheFactory.createCache(configFile, toStart);
+ cache.start();
+
+ System.setProperty(Context.INITIAL_CONTEXT_FACTORY, FACTORY);
+
+ tx_mgr = DummyTransactionManager.getInstance();
+ t1_ex = t2_ex = null;
+ }
+
+ @AfterMethod(alwaysRun = true)
+ protected void tearDown() throws Exception
+ {
+ cache.stop();
+
+ DummyTransactionManager.destroy();
+ }
+
+// public void testDummy() {}
+
+ UserTransaction getTransaction() throws SystemException, NotSupportedException,
NamingException
+ {
+ Properties prop = new Properties();
+ prop.put(Context.INITIAL_CONTEXT_FACTORY,
+ "org.jboss.cache.transaction.DummyContextFactory");
+ return (UserTransaction) new
InitialContext(prop).lookup("UserTransaction");
+ }
+
+ private Person createPerson(String id, String name, int age)
+ {
+ Person p = new Person();
+ p.setName(name);
+ p.setAge(age);
+ cache.attach(id, p);
+ return p;
+ }
+
+ public void testSimple() throws Exception
+ {
+ log.info("testSimple() ....");
+ UserTransaction tx = getTransaction();
+ tx.begin();
+ Person p = createPerson("/person/test1", "Harald Gliebe", 32);
+ tx.commit();
+ tx.begin();
+ p.setName("Benoit");
+ tx.commit();
+ Person p1 = (Person) cache.find("/person/test1");
+ assertEquals("Benoit", p.getName());
+ assertEquals("Benoit", p1.getName());
+ tx.begin();
+ p1.setAge(61);
+ tx.commit();
+ assertEquals(61, p.getAge());
+ assertEquals(61, p1.getAge());
+ }
+
+ public void testModification() throws Exception
+ {
+ UserTransaction tx = getTransaction();
+ tx.begin();
+ Person p = createPerson("/person/test2", "Harald", 32);
+ p.setName("Harald Gliebe");
+ tx.commit();
+ Person p1 = (Person) cache.find("/person/test2");
+ tx.begin();
+ p1.setName("Benoit");
+ tx.commit();
+ assertEquals(p.getName(), "Benoit");
+ assertEquals(p1.getName(), "Benoit");
+ tx.begin();
+ p1.setName("Harald");
+ tx.rollback();
+ assertEquals(p.getName(), "Benoit");
+ assertEquals(p1.getName(), "Benoit");
+ }
+
+ public void testConcurrentSimplePuts() throws Exception
+ {
+ Thread t1 = new Thread("t1")
+ {
+ public void run()
+ {
+ try
+ {
+ Person p = (Person) cache.find("/person/test6");
+ Address addr = new Address();
+ addr.setCity("San Jose");
+ UserTransaction tx = getTransaction();
+ tx.begin();
+ // Note that this will create a write lock on p (on the JBossInternal
node)
+ p.setAddress(addr);
+ TestingUtil.sleepThread(17000);
+ tx.commit();
+ }
+ catch (RollbackException rollback)
+ {
+ ;
+ }
+ catch (Exception ex)
+ {
+ t1_ex = ex;
+ }
+ }
+ };
+
+ Thread t2 = new Thread("t2")
+ {
+ public void run()
+ {
+ UserTransaction tx = null;
+ try
+ {
+ TestingUtil.sleepThread(1000); // give Thread1 time to createPerson
+ Person p = (Person) cache.find("/person/test6");
+ Address addr = new Address();
+ addr.setCity("Santa Clara");
+ tx = getTransaction();
+ tx.begin();
+ p.setAddress(addr);
+ tx.commit();
+ }
+ catch (RollbackException rollback)
+ {
+ ;
+ }
+ catch (org.jboss.cache.pojo.PojoCacheException tex)
+ {
+ // This will be a timeout exception. OK.
+ }
+ catch (Exception ex)
+ {
+// t2_ex = ex;
+ if (tx != null)
+ {
+ try
+ {
+ tx.rollback();
+ }
+ catch (SystemException e)
+ {
+ e.printStackTrace();
+ t2_ex = e;
+ }
+ }
+ t2_ex = ex;
+ ex.printStackTrace();
+ }
+ }
+ };
+
+ Person p = createPerson("/person/test6", "p6", 50);
+
+ t1.start();
+ t2.start();
+
+ t1.join();
+ t2.join();
+
+ // t2 should rollback due to timeout while t2 should succeed
+ if (t2_ex != null)
+ fail("Thread1 failed: " + t2_ex);
+ if (t1_ex != null)
+ fail("Thread2 failed: " + t1_ex);
+
+ assertEquals("City ", "San Jose", p.getAddress().getCity());
+ }
+
+ public void testConcurrentPuts() throws Exception
+ {
+ Thread t1 = new Thread("t1")
+ {
+ public void run()
+ {
+ try
+ {
+ List<String> lang = ((Person)
cache.find("/person/test6")).getLanguages();
+ UserTransaction tx = getTransaction();
+ tx.begin();
+ lang.add("German");
+ TestingUtil.sleepThread(17000);
+ tx.commit();
+ }
+ catch (RollbackException rollback)
+ {
+ ;
+ }
+ catch (Exception ex)
+ {
+ t1_ex = ex;
+ }
+ }
+ };
+
+ Thread t2 = new Thread("t2")
+ {
+ public void run()
+ {
+ UserTransaction tx = null;
+ try
+ {
+ TestingUtil.sleepThread(1000); // give Thread1 time to createPerson
+ List<String> lang = ((Person)
cache.find("/person/test6")).getLanguages();
+ tx = getTransaction();
+ tx.begin();
+ lang.add("English");
+ tx.commit();
+ }
+ catch (RollbackException rollback)
+ {
+ ;
+ }
+ catch (org.jboss.cache.lock.TimeoutException tex)
+ {
+ //
+ }
+ catch (Exception ex)
+ {
+ if (tx != null)
+ {
+ try
+ {
+ tx.rollback();
+ }
+ catch (SystemException e)
+ {
+ e.printStackTrace();
+ t2_ex = e;
+ }
+ }
+ t2_ex = ex;
+ ex.printStackTrace();
+ }
+ }
+ };
+
+ Person p = createPerson("/person/test6", "p6", 50);
+ List<String> lang = new ArrayList<String>();
+ lang.add("German");
+ p.setLanguages(lang);
+
+ t1.start();
+ t2.start();
+
+ t1.join();
+ t2.join();
+
+ // t2 should rollback due to timeout while t2 should succeed
+ if (t2_ex != null)
+ fail("Thread1 failed: " + t2_ex);
+ if (t1_ex != null)
+ fail("Thread2 failed: " + t1_ex);
+
+ int size = ((Person) cache.find("/person/test6")).getLanguages().size();
+ assertEquals("number of languages ",
+ 2, size);
+ }
+
+ public void testConcurrentPutsNoWait() throws Exception
+ {
+ Thread t1 = new Thread("t1")
+ {
+ UserTransaction tx;
+
+ public void run()
+ {
+ try
+ {
+ for (int i = 0; i < 100; i++)
+ {
+ String id = "/p1/test7";
+ Person p = createPerson(id, "p6", 50);
+ cache.detach(id);
+ p = createPerson(id, "p6", 51);
+ List<String> lang = new ArrayList<String>();
+ tx = getTransaction();
+ tx.begin();
+ lang.add("German");
+ lang.add("English");
+ try
+ {
+ p.setLanguages(lang);
+ }
+ catch (PojoCacheException ex)
+ {
+ ex.printStackTrace();
+ }
+ tx.commit();
+ TestingUtil.sleepThread(20); // give Thread1 time to createPerson
+ }
+ }
+ catch (RollbackException rollback)
+ {
+ rollback.printStackTrace();
+ }
+ catch (PojoCacheException pe)
+ {
+ pe.printStackTrace();
+ }
+ catch (Exception ex)
+ {
+ t1_ex = ex;
+ }
+ }
+ };
+
+ Thread t2 = new Thread("t2")
+ {
+ UserTransaction tx;
+
+ public void run()
+ {
+ try
+ {
+ for (int i = 0; i < 100; i++)
+ {
+ String id = "/p1/test8";
+ Person p = createPerson(id, "p6", 50);
+ cache.detach(id);
+ p = createPerson(id, "p6", 51);
+ List<String> lang = new ArrayList<String>();
+ tx = getTransaction();
+ tx.begin();
+ lang.add("German");
+ lang.add("English");
+ try
+ {
+ p.setLanguages(lang);
+ }
+ catch (PojoCacheException ex)
+ {
+ ex.printStackTrace();
+ }
+ tx.commit();
+ TestingUtil.sleepThread(20); // give Thread1 time to createPerson
+ }
+ }
+ catch (RollbackException rollback)
+ {
+ rollback.printStackTrace();
+ }
+ catch (PojoCacheException pe)
+ {
+ pe.printStackTrace();
+ }
+ catch (Exception ex)
+ {
+ t2_ex = ex;
+ ex.printStackTrace();
+ }
+ }
+ };
+
+ createPerson("/p1/test6", "p6", 50);
+ createPerson("/p2/test6", "p6", 50);
+
+ t1.start();
+ t2.start();
+
+ t1.join();
+ t2.join();
+
+ // t2 should rollback due to timeout while t2 should succeed
+ if (t2_ex != null)
+ fail("Thread1 failed: " + t2_ex);
+ if (t1_ex != null)
+ fail("Thread2 failed: " + t1_ex);
+
+// int size = ((Person) cache.find("/p1/test7")).getLanguages().size();
+// assertEquals("number of languages ",
+// 2, size);
+ }
+
+ void log(String s)
+ {
+ long now;
+ if (start == 0)
+ start = System.currentTimeMillis();
+ now = System.currentTimeMillis();
+
+ System.out.println("[" + Thread.currentThread().getName() + "]
[" + (now - start) + "] " + s);
+ }
+
+
+
+
+
+}
Deleted: pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/NewReplicatedTest.java
===================================================================
--- pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/NewReplicatedTest.java 2007-11-26
18:16:13 UTC (rev 4776)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/NewReplicatedTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -1,265 +0,0 @@
-package org.jboss.cache.pojo;
-
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.fail;
-
-import java.io.Serializable;
-import java.util.Properties;
-
-import javax.naming.Context;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.config.Configuration.CacheMode;
-import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.pojo.test.Address;
-import org.jboss.cache.pojo.test.Person;
-import org.jboss.cache.pojo.test.SpecialSerializedAddress;
-import org.jboss.cache.pojo.test.Student;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-
-/**
- * Replication PojoCache test. This is the real beef as local mode for PojoCache really
does
- * not do anything.
- *
- * @author Ben Wang
- */
-
-@Test(groups = {"functional"})
-public class NewReplicatedTest
-{
- Log log_ = LogFactory.getLog(NewReplicatedTest.class);
- PojoCache cache_;
- PojoCache cache1_;
-
-
- @BeforeMethod(alwaysRun = true)
- protected void setUp() throws Exception
- {
- Properties prop = new Properties();
- prop.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.cache.transaction.DummyContextFactory");
- boolean toStart = false;
- cache_ =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
- cache1_ =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
- cache_.start();
- cache1_.start();
- }
-
- @AfterMethod(alwaysRun = true)
- protected void tearDown() throws Exception
- {
- cache_.stop();
- cache1_.stop();
- }
-
- /*
- public void testObjectSizePut() throws Exception
- {
- org.jboss.cache.data.Student student =
(org.jboss.cache.data.Student)constructObject();
- cache_.putObject("/joe", student);
- }
-
- static Object constructObject()
- {
- org.jboss.cache.data.Student joe = new org.jboss.cache.data.Student();
- joe.setName("Joe");
-
- Address add = new Address();
- add.setZip(94086);
- add.setCity("Sunnyvale)");
- add.setStreet("Albertson");
- joe.setAddress(add);
-
- String str;
- for(int i=0; i < 100; i++)
- {
- Course course = new Course();
- str = RandomString.randomstring(10,20);
- course.setInstructor(str);
- str = RandomString.randomstring(10,20);
- course.setTitle(str);
- str = RandomString.randomstring(10,20);
- course.setRoom(str);
- joe.addCourse(course);
- }
-
- return joe;
- }
- */
-
-
- public void testSubClass() throws Exception
- {
- log_.info("testsubClass() ....");
- Student test = new Student();
- test.setName("Ben");
- test.setAge(10);
- Address addr = new Address();
- addr.setCity("Taipei");
- addr.setZip(106);
- test.setAddress(addr);
- cache_.attach("/a", test);
- Student result = (Student) cache_.find("/a");
- assertEquals(" ", test, result);
-
- Student remote = (Student) cache1_.find("/a");
- System.out.println("Output on cache1: " + result);
- System.out.println("Output on cache2: " + remote);
- assertEquals("Age should be ", 10, remote.getAge());
- }
-
- public void testRemoteRemove() throws Exception
- {
- log_.info("testRemoteRemove() ....");
- Person test = new Person();
- test.setName("Ben");
- test.setAge(10);
- cache_.attach("/a", test);
- Person result = (Person) cache_.find("/a");
- assertEquals(" ", test, result);
-
- Person remote = (Person) cache1_.find("/a");
- assertEquals("Age should be ", 10, remote.getAge());
-
- // Remote remove
- cache1_.detach("/a");
- assertNull("Object should be null ", cache_.find("/a"));
-
- assertNull("Object should be null ", cache1_.find("/a"));
- // It should still be 10
- assertEquals("Age should be ", 10, remote.getAge());
- }
-
- public void testRemoteRemove2() throws Exception
- {
- log_.info("testRemoteRemove() ....");
- Person test = new Person();
- test.setName("Ben");
- test.setAge(10);
- cache_.attach("/a", test);
- Person result = (Person) cache_.find("/a");
- assertEquals(" ", test, result);
-
- Person remote = (Person) cache1_.find("/a");
- assertEquals("Age should be ", 10, remote.getAge());
-
- // Remote remove
- cache_.detach("/a");
- assertNull("Object should be null ", cache_.find("/a"));
-
- assertNull("Object should be null ", cache1_.find("/a"));
- // this will trigger the PojoCacheAlreadyDetachedException
- try
- {
- remote.getAge();
- fail("Should throw out exception here.");
- }
- catch (PojoCacheAlreadyDetachedException pe)
- {
- }
- }
-
- /**
- * Test for pojo detachment and then serialization.
- *
- * @throws Exception
- */
- public void testRemoteDetach() throws Exception
- {
- log_.info("testRemoteDetach() ....");
- SpecialSerializedAddress addr = new SpecialSerializedAddress();
- addr.setZip(95123);
- addr.addResidents("Ben");
- addr.addResidents("Joe");
- // Test serialization first
- Fqn<String> fqn = Fqn.fromString("/plain");
- cache_.getCache().put(fqn, "test", addr);
- cache_.getCache().remove(fqn, "test");
-
- cache_.attach("/a", addr);
- SpecialSerializedAddress result = (SpecialSerializedAddress)
cache_.find("/a");
- assertEquals(" ", addr, result);
-
- // Remote remove
- cache_.detach("/a");
- assertNull("Object should be null ", cache_.find("/a"));
-
- // Test serialization after detach
- cache_.getCache().put(fqn, "test", addr);
-
- SpecialSerializedAddress remote = (SpecialSerializedAddress)
- cache1_.getCache().get(fqn, "test");
- assertEquals("Name should be ", 95123, remote.getZip());
- }
-
- public void testPutArray1() throws Exception
- {
- log_.info("testPutArray1() ....");
- long[] arr = new long[]{1, 2};
- cache_.attach("array", arr);
-
- long[] a2 = (long[]) cache1_.find("array");
- assertEquals("arr 0", 1, a2[0]);
- }
-
- public static class PersonSerial implements Serializable
- {
- private static final long serialVersionUID = 1L;
- public String name;
- public int age;
-
- public PersonSerial(String name, int age)
- {
- this.name = name;
- this.age = age;
- }
- }
-
- public void testPutArray2() throws Exception
- {
- log_.info("testPutArray2() ....");
- PersonSerial p1 = new PersonSerial("Ben", 10);
-
- PersonSerial p2 = new PersonSerial("Joe", 20);
- PersonSerial[] arr = new PersonSerial[]{p1, p2};
-
- cache_.attach("array", arr);
-
- PersonSerial[] a2 = (PersonSerial[]) cache1_.find("array");
- assertEquals("arr 0", "Ben", a2[0].name);
- }
-
- /**
- * JBCACHE-200.
- *
- * @throws Exception
- */
- public void testStateTransfer() throws Exception
- {
- log_.info("testStateTransfer() ....");
- Person test = new Person();
- test.setName("Ben");
- test.setAge(10);
- cache_.attach("/a", test);
- Person result = (Person) cache_.find("/a");
- assertEquals(" ", test, result);
-
- // restart cache1_
- cache1_.stop();
- cache1_.getCache().removeNode(Fqn.fromString("/a"));
- cache1_.start();
- // Start from scratch for initial state transfer
- Person remote = (Person) cache1_.find("/a");
- assertEquals("Age should be ", 10, remote.getAge());
- }
-
-
-
-
-}
-
Copied: pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/NewReplicatedTest.java
(from rev 5139,
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/NewReplicatedTest.java)
===================================================================
--- pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/NewReplicatedTest.java
(rev 0)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/NewReplicatedTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -0,0 +1,265 @@
+package org.jboss.cache.pojo;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNull;
+import static org.testng.AssertJUnit.fail;
+
+import java.io.Serializable;
+import java.util.Properties;
+
+import javax.naming.Context;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.pojo.test.Address;
+import org.jboss.cache.pojo.test.Person;
+import org.jboss.cache.pojo.test.SpecialSerializedAddress;
+import org.jboss.cache.pojo.test.Student;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+
+/**
+ * Replication PojoCache test. This is the real beef as local mode for PojoCache really
does
+ * not do anything.
+ *
+ * @author Ben Wang
+ */
+
+@Test(groups = {"functional"}, enabled=false)
+public class NewReplicatedTest
+{
+ Log log_ = LogFactory.getLog(NewReplicatedTest.class);
+ PojoCache cache_;
+ PojoCache cache1_;
+
+
+ @BeforeMethod(alwaysRun = true)
+ protected void setUp() throws Exception
+ {
+ Properties prop = new Properties();
+ prop.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.cache.transaction.DummyContextFactory");
+ boolean toStart = false;
+ cache_ =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
+ cache1_ =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
+ cache_.start();
+ cache1_.start();
+ }
+
+ @AfterMethod(alwaysRun = true)
+ protected void tearDown() throws Exception
+ {
+ cache_.stop();
+ cache1_.stop();
+ }
+
+ /*
+ public void testObjectSizePut() throws Exception
+ {
+ org.jboss.cache.data.Student student =
(org.jboss.cache.data.Student)constructObject();
+ cache_.putObject("/joe", student);
+ }
+
+ static Object constructObject()
+ {
+ org.jboss.cache.data.Student joe = new org.jboss.cache.data.Student();
+ joe.setName("Joe");
+
+ Address add = new Address();
+ add.setZip(94086);
+ add.setCity("Sunnyvale)");
+ add.setStreet("Albertson");
+ joe.setAddress(add);
+
+ String str;
+ for(int i=0; i < 100; i++)
+ {
+ Course course = new Course();
+ str = RandomString.randomstring(10,20);
+ course.setInstructor(str);
+ str = RandomString.randomstring(10,20);
+ course.setTitle(str);
+ str = RandomString.randomstring(10,20);
+ course.setRoom(str);
+ joe.addCourse(course);
+ }
+
+ return joe;
+ }
+ */
+
+
+ public void testSubClass() throws Exception
+ {
+ log_.info("testsubClass() ....");
+ Student test = new Student();
+ test.setName("Ben");
+ test.setAge(10);
+ Address addr = new Address();
+ addr.setCity("Taipei");
+ addr.setZip(106);
+ test.setAddress(addr);
+ cache_.attach("/a", test);
+ Student result = (Student) cache_.find("/a");
+ assertEquals(" ", test, result);
+
+ Student remote = (Student) cache1_.find("/a");
+ System.out.println("Output on cache1: " + result);
+ System.out.println("Output on cache2: " + remote);
+ assertEquals("Age should be ", 10, remote.getAge());
+ }
+
+ public void testRemoteRemove() throws Exception
+ {
+ log_.info("testRemoteRemove() ....");
+ Person test = new Person();
+ test.setName("Ben");
+ test.setAge(10);
+ cache_.attach("/a", test);
+ Person result = (Person) cache_.find("/a");
+ assertEquals(" ", test, result);
+
+ Person remote = (Person) cache1_.find("/a");
+ assertEquals("Age should be ", 10, remote.getAge());
+
+ // Remote remove
+ cache1_.detach("/a");
+ assertNull("Object should be null ", cache_.find("/a"));
+
+ assertNull("Object should be null ", cache1_.find("/a"));
+ // It should still be 10
+ assertEquals("Age should be ", 10, remote.getAge());
+ }
+
+ public void testRemoteRemove2() throws Exception
+ {
+ log_.info("testRemoteRemove() ....");
+ Person test = new Person();
+ test.setName("Ben");
+ test.setAge(10);
+ cache_.attach("/a", test);
+ Person result = (Person) cache_.find("/a");
+ assertEquals(" ", test, result);
+
+ Person remote = (Person) cache1_.find("/a");
+ assertEquals("Age should be ", 10, remote.getAge());
+
+ // Remote remove
+ cache_.detach("/a");
+ assertNull("Object should be null ", cache_.find("/a"));
+
+ assertNull("Object should be null ", cache1_.find("/a"));
+ // this will trigger the PojoCacheAlreadyDetachedException
+ try
+ {
+ remote.getAge();
+ fail("Should throw out exception here.");
+ }
+ catch (PojoCacheAlreadyDetachedException pe)
+ {
+ }
+ }
+
+ /**
+ * Test for pojo detachment and then serialization.
+ *
+ * @throws Exception
+ */
+ public void testRemoteDetach() throws Exception
+ {
+ log_.info("testRemoteDetach() ....");
+ SpecialSerializedAddress addr = new SpecialSerializedAddress();
+ addr.setZip(95123);
+ addr.addResidents("Ben");
+ addr.addResidents("Joe");
+ // Test serialization first
+ Fqn<String> fqn = Fqn.fromString("/plain");
+ cache_.getCache().put(fqn, "test", addr);
+ cache_.getCache().remove(fqn, "test");
+
+ cache_.attach("/a", addr);
+ SpecialSerializedAddress result = (SpecialSerializedAddress)
cache_.find("/a");
+ assertEquals(" ", addr, result);
+
+ // Remote remove
+ cache_.detach("/a");
+ assertNull("Object should be null ", cache_.find("/a"));
+
+ // Test serialization after detach
+ cache_.getCache().put(fqn, "test", addr);
+
+ SpecialSerializedAddress remote = (SpecialSerializedAddress)
+ cache1_.getCache().get(fqn, "test");
+ assertEquals("Name should be ", 95123, remote.getZip());
+ }
+
+ public void testPutArray1() throws Exception
+ {
+ log_.info("testPutArray1() ....");
+ long[] arr = new long[]{1, 2};
+ cache_.attach("array", arr);
+
+ long[] a2 = (long[]) cache1_.find("array");
+ assertEquals("arr 0", 1, a2[0]);
+ }
+
+ public static class PersonSerial implements Serializable
+ {
+ private static final long serialVersionUID = 1L;
+ public String name;
+ public int age;
+
+ public PersonSerial(String name, int age)
+ {
+ this.name = name;
+ this.age = age;
+ }
+ }
+
+ public void testPutArray2() throws Exception
+ {
+ log_.info("testPutArray2() ....");
+ PersonSerial p1 = new PersonSerial("Ben", 10);
+
+ PersonSerial p2 = new PersonSerial("Joe", 20);
+ PersonSerial[] arr = new PersonSerial[]{p1, p2};
+
+ cache_.attach("array", arr);
+
+ PersonSerial[] a2 = (PersonSerial[]) cache1_.find("array");
+ assertEquals("arr 0", "Ben", a2[0].name);
+ }
+
+ /**
+ * JBCACHE-200.
+ *
+ * @throws Exception
+ */
+ public void testStateTransfer() throws Exception
+ {
+ log_.info("testStateTransfer() ....");
+ Person test = new Person();
+ test.setName("Ben");
+ test.setAge(10);
+ cache_.attach("/a", test);
+ Person result = (Person) cache_.find("/a");
+ assertEquals(" ", test, result);
+
+ // restart cache1_
+ cache1_.stop();
+ //cache1_.getCache().removeNode(Fqn.fromString("/a"));
+ cache1_.start();
+ // Start from scratch for initial state transfer
+ Person remote = (Person) cache1_.find("/a");
+ assertEquals("Age should be ", 10, remote.getAge());
+ }
+
+
+
+
+}
+
Deleted: pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/NewReplicatedTxTest.java
===================================================================
---
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/NewReplicatedTxTest.java 2007-11-26
18:16:13 UTC (rev 4776)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/NewReplicatedTxTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -1,441 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at
gnu.org.
- */
-
-package org.jboss.cache.pojo;
-
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.fail;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.transaction.NotSupportedException;
-import javax.transaction.RollbackException;
-import javax.transaction.SystemException;
-import javax.transaction.UserTransaction;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.config.Configuration.CacheMode;
-import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.pojo.test.Address;
-import org.jboss.cache.pojo.test.Person;
-import org.jboss.cache.transaction.DummyTransactionManager;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-/**
- * PojoCache replicated test cases with tx.
- *
- * @author Ben Wang
- */
-
-@Test(groups = {"functional"})
-public class NewReplicatedTxTest
-{
- Log log = LogFactory.getLog(NewReplicatedTxTest.class);
- PojoCache cache_;
- PojoCache cache1_;
- final String FACTORY = "org.jboss.cache.transaction.DummyContextFactory";
- DummyTransactionManager tx_mgr;
- Throwable t1_ex, t2_ex;
- long start = 0;
-
-
-
- @BeforeMethod(alwaysRun = true)
- protected void setUp() throws Exception
- {
- log.info("setUp() ....");
- Properties prop = new Properties();
- prop.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.cache.transaction.DummyContextFactory");
- boolean toStart = false;
- cache_ =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
- cache1_ =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
- cache_.start();
- cache1_.start();
-
- tx_mgr = DummyTransactionManager.getInstance();
- t1_ex = t2_ex = null;
- }
-
- @AfterMethod(alwaysRun = true)
- protected void tearDown() throws Exception
- {
- cache_.stop();
- cache1_.stop();
- DummyTransactionManager.destroy();
- }
-
- UserTransaction getTransaction() throws SystemException, NotSupportedException,
NamingException
- {
- Properties prop = new Properties();
- prop.put(Context.INITIAL_CONTEXT_FACTORY,
- "org.jboss.cache.transaction.DummyContextFactory");
- return (UserTransaction) new
InitialContext(prop).lookup("UserTransaction");
- }
-
- public void testSimpleTxWithRollback() throws Exception
- {
- log.info("testSimpleTxWithRollback() ....");
- UserTransaction tx = getTransaction();
-
- Person joe = new Person();
- joe.setName("Joe");
- Address add = new Address();
- add.setZip(104);
- add.setCity("Taipei");
- joe.setAddress(add);
-
- tx.begin();
- cache_.attach("/person/joe", joe);
- tx.commit();
- Person p = (Person) cache1_.find("/person/joe");
- assertEquals("Zip should be the same ", joe.getAddress().getZip(),
p.getAddress().getZip());
-
- // test rollback
- Person ben = new Person();
- ben.setName("Ben");
- add = new Address();
- add.setZip(104);
- add.setCity("Taipei");
- joe.setAddress(add);
- tx.begin();
- cache_.attach("/person/ben", ben);
- tx.rollback();
- assertEquals("Zip should be the same ", joe.getAddress().getZip(),
p.getAddress().getZip());
- }
-
- public void testCollectionTxWithRollback() throws Exception
- {
- log.info("testCollectionTxWithRollback() ....");
- UserTransaction tx = getTransaction();
-
- Person joe = new Person();
- joe.setName("Joe");
- Address add = new Address();
- add.setZip(104);
- add.setCity("Taipei");
- joe.setAddress(add);
- ArrayList<String> lang = new ArrayList<String>();
- lang.add("English");
- lang.add("Taiwanese");
- lang.add("Mandirin");
- joe.setLanguages(lang);
-
- tx.begin();
- cache_.attach("/person/joe", joe);
- tx.commit();
- Person p = (Person) cache1_.find("/person/joe");
- assertEquals("Zip should be the same ", joe.getAddress().getZip(),
p.getAddress().getZip());
-
- // test rollback
- Person ben = new Person();
- ben.setName("Ben");
- add = new Address();
- add.setZip(104);
- add.setCity("Taipei");
- ben.setAddress(add);
- tx.begin();
- cache_.attach("/person/ben", ben);
- tx.rollback();
- assertEquals("Zip should be the same ", joe.getAddress().getZip(),
p.getAddress().getZip());
- assertEquals("Langue 1 should be: ", "English",
joe.getLanguages().get(0));
- }
-
-
- public void testConcurrentPutsWithRollback() throws Exception
- {
- Thread t1 = new Thread()
- {
- public void run()
- {
- Person p = new Person();
- p.setName("Ben");
- Address add = new Address();
- add.setCity("Taipei");
- p.setAddress(add);
- List<String> lang = new ArrayList<String>();
- lang.add("English");
- lang.add("Taiwanese");
- lang.add("Japanese");
- p.setLanguages(lang);
- try
- {
- cache_.attach("/test/ben", p);
- }
- catch (Exception ex)
- {
- try
- {
- throw new RuntimeException("PojoCache is not rolling back properly
for Collection yet.");
- // cache_.attach("/test/ben", p);
- }
- catch (Exception ex1)
- {
- t1_ex = ex1;
- }
- }
- }
- };
-
- Thread t2 = new Thread()
- {
- public void run()
- {
- try
- {
- UserTransaction tx = getTransaction();
- tx.begin();
- Person p = new Person();
- p.setName("Ben");
- Address add = new Address();
- add.setCity("Taipei");
- p.setAddress(add);
- cache1_.attach("/test/ben", p);
- TestingUtil.sleepThread(1000);
- tx.commit();
- }
- catch (RollbackException rollback)
- {
- }
- catch (Exception ex)
- {
- t2_ex = ex;
- }
- }
- };
-
- t1.start();
- t2.start();
-
- t1.join();
- t2.join();
-
- // t2 should rollback due to timeout while t2 should succeed
- if (t1_ex != null)
- {
- fail("Thread1 failed: " + t1_ex);
- }
- if (t2_ex != null)
- {
- fail("Thread2 failed: " + t2_ex);
- }
- }
-
- public void testConcurrentTxPutsWithRollback() throws Exception
- {
- Thread t1 = new Thread()
- {
- public void run()
- {
- UserTransaction tx = null;
- Person p = new Person();
- p.setName("Ben");
- Address add = new Address();
- add.setCity("Taipei");
- p.setAddress(add);
- List<String> lang = new ArrayList<String>();
- lang.add("English");
- lang.add("Taiwanese");
- lang.add("Japanese");
- p.setLanguages(lang);
- try
- {
- tx = getTransaction();
- tx.begin();
- cache_.attach("/test/ben", p);
- TestingUtil.sleepThread(500);
- tx.commit();
- }
- catch (RollbackException rollback)
- {
- try
- {
- tx = getTransaction();
- tx.begin();
- // throw new RuntimeException("PojoCache is not
rolling back properly for Collection yet.");
- cache_.attach("/test/ben", p);
- tx.commit();
- }
- catch (Exception ex)
- {
- t1_ex = ex;
- ex.printStackTrace();
- }
- }
- catch (Exception ex)
- {
- t1_ex = ex;
- ex.printStackTrace();
- }
- }
- };
-
- Thread t2 = new Thread()
- {
- public void run()
- {
- try
- {
- UserTransaction tx = getTransaction();
- tx.begin();
- Person p = new Person();
- p.setName("Ben");
- Address add = new Address();
- add.setCity("Taipei");
- p.setAddress(add);
- cache1_.attach("/test/ben", p);
- TestingUtil.sleepThread(1000);
- tx.commit();
- }
- catch (RollbackException rollback)
- {
- }
- catch (Exception ex)
- {
- t2_ex = ex;
- }
- }
- };
-
- t1.start();
- t2.start();
-
- t1.join();
- t2.join();
-
- // t2 should rollback due to timeout while t2 should succeed
- if (t1_ex != null)
- {
- fail("Thread1 failed: " + t1_ex);
- }
- if (t2_ex != null)
- {
- fail("Thread2 failed: " + t2_ex);
- }
- }
-
- public void testConcurrentTxPutsWithRollbackField() throws Exception
- {
- Person p = new Person();
- p.setName("Ben");
- Address add = new Address();
- add.setCity("Taipei");
- p.setAddress(add);
- List<String> lang = new ArrayList<String>();
- lang.add("1");
- p.setLanguages(lang);
- cache_.attach("/test/ben", p);
-
- Thread t1 = new Thread()
- {
- public void run()
- {
- UserTransaction tx = null;
- List<String> lang = null;
- try
- {
- Person ben = (Person) cache_.find("/test/ben");
- lang = ben.getLanguages();
-
- tx = getTransaction();
- tx.begin();
- lang.add("2");
- lang.add("3");
- lang.remove(0);
- TestingUtil.sleepThread(1000);
- tx.commit();
- }
- catch (RollbackException rollback)
- {
- try
- {
- tx = getTransaction();
- tx.begin();
- lang.add("2");
- lang.add("3");
- lang.remove(0);
- tx.commit();
- }
- catch (Exception ex)
- {
- t1_ex = ex;
- }
- }
- catch (Exception ex)
- {
- t1_ex = ex;
- }
- }
- };
-
- Thread t2 = new Thread()
- {
- public void run()
- {
- List<String> lang = null;
- UserTransaction tx = null;
- try
- {
- Person ben = (Person) cache1_.find("/test/ben");
- lang = ben.getLanguages();
-
- tx = getTransaction();
- tx.begin();
- lang.add("2");
- TestingUtil.sleepThread(1000);
- tx.commit();
- }
- catch (RollbackException rollback)
- {
- TestingUtil.sleepThread(1000);
- try
- {
- tx = getTransaction();
- tx.begin();
- lang.add("2");
- tx.commit();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- catch (Exception ex)
- {
- t2_ex = ex;
- }
- }
- };
-
- t1.start();
- t2.start();
-
- t1.join();
- t2.join();
-
- // t2 should rollback due to timeout while t2 should succeed
- if (t1_ex != null)
- {
- fail("Thread1 failed: " + t1_ex);
- }
- if (t2_ex != null)
- {
- fail("Thread2 failed: " + t2_ex);
- }
- }
-
-
-
-
-}
Copied: pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/NewReplicatedTxTest.java
(from rev 5139,
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/NewReplicatedTxTest.java)
===================================================================
--- pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/NewReplicatedTxTest.java
(rev 0)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/NewReplicatedTxTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -0,0 +1,442 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at
gnu.org.
+ */
+
+package org.jboss.cache.pojo;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+import javax.transaction.UserTransaction;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.pojo.test.Address;
+import org.jboss.cache.pojo.test.Person;
+import org.jboss.cache.transaction.DummyTransactionManager;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * PojoCache replicated test cases with tx.
+ *
+ * @author Ben Wang
+ */
+
+@Test(groups = {"functional"}, enabled=false)
+public class NewReplicatedTxTest
+{
+ Log log = LogFactory.getLog(NewReplicatedTxTest.class);
+ PojoCache cache_;
+ PojoCache cache1_;
+ final String FACTORY = "org.jboss.cache.transaction.DummyContextFactory";
+ DummyTransactionManager tx_mgr;
+ Throwable t1_ex, t2_ex;
+ long start = 0;
+
+
+
+ @BeforeMethod(alwaysRun = true)
+ protected void setUp() throws Exception
+ {
+ log.info("setUp() ....");
+ Properties prop = new Properties();
+ prop.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.cache.transaction.DummyContextFactory");
+ boolean toStart = false;
+ cache_ =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
+ cache1_ =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
+ cache_.start();
+ cache1_.start();
+
+ tx_mgr = DummyTransactionManager.getInstance();
+ t1_ex = t2_ex = null;
+ }
+
+ @AfterMethod(alwaysRun = true)
+ protected void tearDown() throws Exception
+ {
+ cache_.stop();
+ cache1_.stop();
+ DummyTransactionManager.destroy();
+ }
+
+ UserTransaction getTransaction() throws SystemException, NotSupportedException,
NamingException
+ {
+ Properties prop = new Properties();
+ prop.put(Context.INITIAL_CONTEXT_FACTORY,
+ "org.jboss.cache.transaction.DummyContextFactory");
+ return (UserTransaction) new
InitialContext(prop).lookup("UserTransaction");
+ }
+
+ public void testSimpleTxWithRollback() throws Exception
+ {
+ log.info("testSimpleTxWithRollback() ....");
+ UserTransaction tx = getTransaction();
+
+ Person joe = new Person();
+ joe.setName("Joe");
+ Address add = new Address();
+ add.setZip(104);
+ add.setCity("Taipei");
+ joe.setAddress(add);
+
+ tx.begin();
+ cache_.attach("/person/joe", joe);
+ tx.commit();
+ Person p = (Person) cache1_.find("/person/joe");
+ assertEquals("Zip should be the same ", joe.getAddress().getZip(),
p.getAddress().getZip());
+
+ // test rollback
+ Person ben = new Person();
+ ben.setName("Ben");
+ add = new Address();
+ add.setZip(104);
+ add.setCity("Taipei");
+ joe.setAddress(add);
+ tx.begin();
+ cache_.attach("/person/ben", ben);
+ tx.rollback();
+ assertEquals("Zip should be the same ", joe.getAddress().getZip(),
p.getAddress().getZip());
+ }
+
+ public void testCollectionTxWithRollback() throws Exception
+ {
+ log.info("testCollectionTxWithRollback() ....");
+ UserTransaction tx = getTransaction();
+
+ Person joe = new Person();
+ joe.setName("Joe");
+ Address add = new Address();
+ add.setZip(104);
+ add.setCity("Taipei");
+ joe.setAddress(add);
+ ArrayList<String> lang = new ArrayList<String>();
+ lang.add("English");
+ lang.add("Taiwanese");
+ lang.add("Mandirin");
+ joe.setLanguages(lang);
+
+ tx.begin();
+ cache_.attach("/person/joe", joe);
+ tx.commit();
+ Person p = (Person) cache1_.find("/person/joe");
+ assertEquals("Zip should be the same ", joe.getAddress().getZip(),
p.getAddress().getZip());
+
+ // test rollback
+ Person ben = new Person();
+ ben.setName("Ben");
+ add = new Address();
+ add.setZip(104);
+ add.setCity("Taipei");
+ ben.setAddress(add);
+ tx.begin();
+ cache_.attach("/person/ben", ben);
+ tx.rollback();
+ assertEquals("Zip should be the same ", joe.getAddress().getZip(),
p.getAddress().getZip());
+ assertEquals("Langue 1 should be: ", "English",
joe.getLanguages().get(0));
+ }
+
+
+ public void testConcurrentPutsWithRollback() throws Exception
+ {
+ Thread t1 = new Thread()
+ {
+ public void run()
+ {
+ Person p = new Person();
+ p.setName("Ben");
+ Address add = new Address();
+ add.setCity("Taipei");
+ p.setAddress(add);
+ List<String> lang = new ArrayList<String>();
+ lang.add("English");
+ lang.add("Taiwanese");
+ lang.add("Japanese");
+ p.setLanguages(lang);
+ try
+ {
+ cache_.attach("/test/ben", p);
+ }
+ catch (Exception ex)
+ {
+ try
+ {
+ throw new RuntimeException("PojoCache is not rolling back properly
for Collection yet.");
+ // cache_.attach("/test/ben", p);
+ }
+ catch (Exception ex1)
+ {
+ t1_ex = ex1;
+ }
+ }
+ }
+ };
+
+ Thread t2 = new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ UserTransaction tx = getTransaction();
+ tx.begin();
+ Person p = new Person();
+ p.setName("Ben");
+ Address add = new Address();
+ add.setCity("Taipei");
+ p.setAddress(add);
+ cache1_.attach("/test/ben", p);
+ TestingUtil.sleepThread(1000);
+ tx.commit();
+ }
+ catch (RollbackException rollback)
+ {
+ }
+ catch (Exception ex)
+ {
+ t2_ex = ex;
+ }
+ }
+ };
+
+ t1.start();
+ t2.start();
+
+ t1.join();
+ t2.join();
+
+ // t2 should rollback due to timeout while t2 should succeed
+ if (t1_ex != null)
+ {
+ fail("Thread1 failed: " + t1_ex);
+ }
+ if (t2_ex != null)
+ {
+ fail("Thread2 failed: " + t2_ex);
+ }
+ }
+
+ public void testConcurrentTxPutsWithRollback() throws Exception
+ {
+ Thread t1 = new Thread()
+ {
+ public void run()
+ {
+ UserTransaction tx = null;
+ Person p = new Person();
+ p.setName("Ben");
+ Address add = new Address();
+ add.setCity("Taipei");
+ p.setAddress(add);
+ List<String> lang = new ArrayList<String>();
+ lang.add("English");
+ lang.add("Taiwanese");
+ lang.add("Japanese");
+ p.setLanguages(lang);
+ try
+ {
+ tx = getTransaction();
+ tx.begin();
+ cache_.attach("/test/ben", p);
+ TestingUtil.sleepThread(500);
+ tx.commit();
+ }
+ catch (RollbackException rollback)
+ {
+ try
+ {
+ tx = getTransaction();
+ tx.begin();
+ // throw new RuntimeException("PojoCache is not
rolling back properly for Collection yet.");
+ cache_.attach("/test/ben", p);
+ tx.commit();
+ }
+ catch (Exception ex)
+ {
+ t1_ex = ex;
+ ex.printStackTrace();
+ }
+ }
+ catch (Exception ex)
+ {
+ t1_ex = ex;
+ ex.printStackTrace();
+ }
+ }
+ };
+
+ Thread t2 = new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ UserTransaction tx = getTransaction();
+ tx.begin();
+ Person p = new Person();
+ p.setName("Ben");
+ Address add = new Address();
+ add.setCity("Taipei");
+ p.setAddress(add);
+ cache1_.attach("/test/ben", p);
+ TestingUtil.sleepThread(1000);
+ tx.commit();
+ }
+ catch (RollbackException rollback)
+ {
+ }
+ catch (Exception ex)
+ {
+ t2_ex = ex;
+ }
+ }
+ };
+
+ t1.start();
+ t2.start();
+
+ t1.join();
+ t2.join();
+
+ // t2 should rollback due to timeout while t2 should succeed
+ if (t1_ex != null)
+ {
+ fail("Thread1 failed: " + t1_ex);
+ }
+ if (t2_ex != null)
+ {
+ fail("Thread2 failed: " + t2_ex);
+ }
+ }
+
+ public void testConcurrentTxPutsWithRollbackField() throws Exception
+ {
+ Person p = new Person();
+ p.setName("Ben");
+ Address add = new Address();
+ add.setCity("Taipei");
+ p.setAddress(add);
+ List<String> lang = new ArrayList<String>();
+ lang.add("1");
+ p.setLanguages(lang);
+ cache_.attach("/test/ben", p);
+
+ Thread t1 = new Thread()
+ {
+ public void run()
+ {
+ UserTransaction tx = null;
+ List<String> lang = null;
+ try
+ {
+ Person ben = (Person) cache_.find("/test/ben");
+ lang = ben.getLanguages();
+
+ tx = getTransaction();
+ tx.begin();
+ lang.add("2");
+ lang.add("3");
+ lang.remove(0);
+ TestingUtil.sleepThread(1000);
+ tx.commit();
+ }
+ catch (RollbackException rollback)
+ {
+ try
+ {
+ tx = getTransaction();
+ tx.begin();
+ lang.add("2");
+ lang.add("3");
+ lang.remove(0);
+ tx.commit();
+ }
+ catch (Exception ex)
+ {
+ t1_ex = ex;
+ }
+ }
+ catch (Exception ex)
+ {
+ t1_ex = ex;
+ }
+ }
+ };
+
+ Thread t2 = new Thread()
+ {
+ public void run()
+ {
+ List<String> lang = null;
+ UserTransaction tx = null;
+ try
+ {
+ Person ben = (Person) cache1_.find("/test/ben");
+ lang = ben.getLanguages();
+
+ tx = getTransaction();
+ tx.begin();
+ lang.add("2");
+ TestingUtil.sleepThread(1000);
+ tx.commit();
+ }
+ catch (RollbackException rollback)
+ {
+ TestingUtil.sleepThread(1000);
+ try
+ {
+ tx = getTransaction();
+ tx.begin();
+ lang.add("2");
+ tx.commit();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ catch (Exception ex)
+ {
+ t2_ex = ex;
+ }
+ }
+ };
+
+ t1.start();
+ t2.start();
+
+ t1.join();
+ t2.join();
+
+ // t2 should rollback due to timeout while t2 should succeed
+ if (t1_ex != null)
+ {
+ fail("Thread1 failed: " + t1_ex);
+ }
+ if (t2_ex != null)
+ {
+ fail("Thread2 failed: " + t2_ex);
+ }
+ }
+
+
+
+
+}
Deleted:
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/ReplicatedCircularGraphTest.java
===================================================================
---
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/ReplicatedCircularGraphTest.java 2007-11-26
18:16:13 UTC (rev 4776)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/ReplicatedCircularGraphTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -1,216 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at
gnu.org.
- */
-
-package org.jboss.cache.pojo;
-
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.config.Configuration.CacheMode;
-import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.pojo.test.Link;
-import org.jboss.cache.pojo.test.NodeManager;
-import org.jboss.cache.pojo.test.Person;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-/**
- * Test object graph handling in aop, e.g., circular reference, multiple reference, link,
etc.
- *
- * @author Ben Wang
- */
-
-@Test(groups = {"functional"})
-public class ReplicatedCircularGraphTest
-{
- Log log = LogFactory.getLog(ReplicatedCircularGraphTest.class);
- PojoCache cache1;
- PojoCache cache2;
-
-
- @BeforeMethod(alwaysRun = true)
- protected void setUp() throws Exception
- {
- log.info("setUp() ....");
- cache1 = createCache("CacheGroup");
- cache2 = createCache("CacheGroup");
- }
-
- @AfterMethod(alwaysRun = true)
- protected void tearDown() throws Exception
- {
- cache1.getCache().removeNode(Fqn.fromString("/"));
- cache1.stop();
- cache2.stop();
- }
-
- private PojoCache createCache(String name) throws Exception
- {
- boolean toStart = false;
- PojoCache tree =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
- tree.start();
- return tree;
- }
-
-// public void testDummy() {}
-
- protected Person createPerson(String name, int age)
- {
- Person p = new Person();
- p.setName(name);
- p.setAge(age);
- return p;
- }
-
- public void testCircularReference1() throws Exception
- {
-// try {Thread.sleep(10000); } catch (Exception e) {};
- log.info("testCircularReference1() ...");
- Link parent = new Link("parent");
- Link child = new Link("child");
- parent.setLink(child);
- child.setLink(parent);
- cache1.attach("/link/parent", parent);
- TestingUtil.sleepThread(100);
- assertEquals("parent", ((Link)
cache1.find("/link/parent")).getName());
- assertEquals("child", ((Link)
cache1.find("/link/parent")).getLink().getName());
- assertEquals("parent", ((Link)
cache2.find("/link/parent")).getName());
- assertEquals("child", ((Link)
cache2.find("/link/parent")).getLink().getName());
- ((Link) cache2.find("/link/parent")).setLink(null);
- assertNull("Child should be null", ((Link)
cache2.find("/link/parent")).getLink());
- Link link = (Link) cache1.detach("/link/parent");
- assertNotNull("Link should not be null ", link);
- System.out.println("Link: " + link);
- }
-
- public void testCircularReference2() throws Exception
- {
-// try {Thread.sleep(10000); } catch (Exception e) {};
- log.info("testCircularReference2() ...");
- Link parent = new Link("parent");
- Link child = new Link("child");
- cache1.attach("/link/parent", parent);
- parent.setLink(child);
- child.setLink(parent);
- assertEquals("parent", ((Link)
cache1.find("/link/parent")).getName());
- assertEquals("child", ((Link)
cache1.find("/link/parent")).getLink().getName());
- assertEquals("parent", ((Link)
cache2.find("/link/parent")).getName());
- assertEquals("child", ((Link)
cache2.find("/link/parent")).getLink().getName());
- ((Link) cache2.find("/link/parent")).setLink(null);
- assertNull("Child should be null", ((Link)
cache2.find("/link/parent")).getLink());
- Link link = (Link) cache1.detach("/link/parent");
- assertNotNull("Link should not be null ", link);
- }
-
- public void testCircularReference3() throws Exception
- {
-// try {Thread.sleep(10000); } catch (Exception e) {};
- log.info("testCircularReference3() ...");
- Link parent = new Link("parent");
- Link child = new Link("child");
- cache1.attach("/link/parent", parent);
- cache1.attach("/link/child", child);
- TestingUtil.sleepThread(100);
- parent.setLink(child);
- child.setLink(parent);
-
- Link p1 = (Link) cache1.find("/link/parent");
- Link c1 = (Link) cache1.find("/link/child");
- assertEquals("parent", p1.getName());
- assertEquals("child", p1.getLink().getName());
- assertEquals("child", c1.getName());
- assertEquals("parent", c1.getLink().getName());
-
- Link p2 = (Link) cache1.find("/link/parent");
- Link c2 = (Link) cache1.find("/link/child");
-
- assertEquals("parent", p2.getName());
- assertEquals("child", p2.getLink().getName());
- assertEquals("child", c2.getName());
- assertEquals("parent", c2.getLink().getName());
-
- p2.setLink(null);
- assertNull("Child should be null", p2.getLink());
- Link link = (Link) cache1.detach("/link/parent");
- assertNotNull("Link should not be null ", link);
- }
-
- /**
- * Setting the circular relationship and also as a shared object.
- *
- * @throws Exception
- */
- public void testCircularReference4() throws Exception
- {
-// try {Thread.sleep(10000); } catch (Exception e) {};
- log.info("testCircularReference3() ...");
- Link parent = new Link("parent");
- Link child = new Link("child");
- parent.setLink(child);
- child.setLink(parent);
-
- List<Link> list = new ArrayList<Link>();
- list.add(parent);
-
- cache1.attach("/list", list);
- cache1.attach("/alias", list);
-
- TestingUtil.sleepThread(100);
- @SuppressWarnings("unchecked")
- List<Link> list1 = (List<Link>) cache2.find("/list");
- @SuppressWarnings("unchecked")
- List<Link> list2 = (List<Link>) cache2.find("/alias");
-
- assertEquals("parent", list1.get(0).getName());
- assertEquals("child", list2.get(0).getLink().getName());
- }
-
- public void testCircularAndSharedReferences() throws Exception
- {
- log.info("testCircularAndSharedReferences() ...");
- NodeManager pm_ = new NodeManager();
-
- pm_.setRootNode("root");
- pm_.addNode("root", "kanto");
- pm_.addNode("root.kanto", "tokyo");
- pm_.addNode("root.kanto", "kanagawa");
-
- cache1.attach("/propagation", pm_);
- assertEquals("kanagawa",
pm_.findNode("root.kanto.kanagawa").getNodeRDN());
- pm_.addNode("root.kanto.tokyo", "hadanshita");
- assertEquals("hadanshita",
pm_.findNode("root.kanto.tokyo.hadanshita").getNodeRDN());
-
- NodeManager pm2_ = (NodeManager) cache2.find("/propagation");
- assertEquals("kanagawa",
pm2_.findNode("root.kanto.kanagawa").getNodeRDN());
- assertEquals("hadanshita",
pm2_.findNode("root.kanto.tokyo.hadanshita").getNodeRDN());
-
-/*
- System.out.println("\n\n");
- System.out.println("---------------------------------------------");
- System.out.println("Initial pm state");
- System.out.println("---------------------------------------------");
- pm_.printNodes();
-
- System.out.println("\n\n");
- System.out.println("---------------------------------------------");
- System.out.println("Initial cache content");
- System.out.println(cache_.printDetails());
- System.out.println("---------------------------------------------");
-*/
- }
-
-
-
-}
Copied:
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/ReplicatedCircularGraphTest.java
(from rev 5129,
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/ReplicatedCircularGraphTest.java)
===================================================================
---
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/ReplicatedCircularGraphTest.java
(rev 0)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/ReplicatedCircularGraphTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -0,0 +1,217 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at
gnu.org.
+ */
+
+package org.jboss.cache.pojo;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.assertNull;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.pojo.test.Link;
+import org.jboss.cache.pojo.test.NodeManager;
+import org.jboss.cache.pojo.test.Person;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Test object graph handling in aop, e.g., circular reference, multiple reference, link,
etc.
+ *
+ * @author Ben Wang
+ */
+
+@Test(groups = {"functional"})
+public class ReplicatedCircularGraphTest
+{
+ Log log = LogFactory.getLog(ReplicatedCircularGraphTest.class);
+ PojoCache cache1;
+ PojoCache cache2;
+
+
+ @BeforeMethod(alwaysRun = true)
+ protected void setUp() throws Exception
+ {
+ log.info("setUp() ....");
+ cache1 = createCache("CacheGroup");
+ cache2 = createCache("CacheGroup");
+ }
+
+ @AfterMethod(alwaysRun = true)
+ protected void tearDown() throws Exception
+ {
+ cache1.getCache().removeNode(Fqn.fromString("/"));
+ cache1.stop();
+ cache2.stop();
+ }
+
+ private PojoCache createCache(String name) throws Exception
+ {
+ boolean toStart = false;
+ PojoCache tree =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
+ tree.start();
+ return tree;
+ }
+
+// public void testDummy() {}
+
+ protected Person createPerson(String name, int age)
+ {
+ Person p = new Person();
+ p.setName(name);
+ p.setAge(age);
+ return p;
+ }
+
+ public void testCircularReference1() throws Exception
+ {
+// try {Thread.sleep(10000); } catch (Exception e) {};
+ log.info("testCircularReference1() ...");
+ Link parent = new Link("parent");
+ Link child = new Link("child");
+ parent.setLink(child);
+ child.setLink(parent);
+ cache1.attach("/link/parent", parent);
+ TestingUtil.sleepThread(100);
+ assertEquals("parent", ((Link)
cache1.find("/link/parent")).getName());
+ assertEquals("child", ((Link)
cache1.find("/link/parent")).getLink().getName());
+ assertEquals("parent", ((Link)
cache2.find("/link/parent")).getName());
+ assertEquals("child", ((Link)
cache2.find("/link/parent")).getLink().getName());
+ ((Link) cache2.find("/link/parent")).setLink(null);
+ assertNull("Child should be null", ((Link)
cache2.find("/link/parent")).getLink());
+ Link link = (Link) cache1.detach("/link/parent");
+ assertNotNull("Link should not be null ", link);
+ System.out.println("Link: " + link);
+ }
+
+ public void testCircularReference2() throws Exception
+ {
+// try {Thread.sleep(10000); } catch (Exception e) {};
+ log.info("testCircularReference2() ...");
+ Link parent = new Link("parent");
+ Link child = new Link("child");
+ cache1.attach("/link/parent", parent);
+ parent.setLink(child);
+ child.setLink(parent);
+ assertEquals("parent", ((Link)
cache1.find("/link/parent")).getName());
+ assertEquals("child", ((Link)
cache1.find("/link/parent")).getLink().getName());
+ assertEquals("parent", ((Link)
cache2.find("/link/parent")).getName());
+ assertEquals("child", ((Link)
cache2.find("/link/parent")).getLink().getName());
+ ((Link) cache2.find("/link/parent")).setLink(null);
+ assertNull("Child should be null", ((Link)
cache2.find("/link/parent")).getLink());
+ Link link = (Link) cache1.detach("/link/parent");
+ assertNotNull("Link should not be null ", link);
+ }
+
+ public void testCircularReference3() throws Exception
+ {
+// try {Thread.sleep(10000); } catch (Exception e) {};
+ log.info("testCircularReference3() ...");
+ Link parent = new Link("parent");
+ Link child = new Link("child");
+ cache1.attach("/link/parent", parent);
+ cache1.attach("/link/child", child);
+ TestingUtil.sleepThread(100);
+ parent.setLink(child);
+ child.setLink(parent);
+
+ Link p1 = (Link) cache1.find("/link/parent");
+ Link c1 = (Link) cache1.find("/link/child");
+ assertEquals("parent", p1.getName());
+ assertEquals("child", p1.getLink().getName());
+ assertEquals("child", c1.getName());
+ assertEquals("parent", c1.getLink().getName());
+
+ Link p2 = (Link) cache1.find("/link/parent");
+ Link c2 = (Link) cache1.find("/link/child");
+
+ assertEquals("parent", p2.getName());
+ assertEquals("child", p2.getLink().getName());
+ assertEquals("child", c2.getName());
+ assertEquals("parent", c2.getLink().getName());
+
+ p2.setLink(null);
+ assertNull("Child should be null", p2.getLink());
+ Link link = (Link) cache1.detach("/link/parent");
+ assertNotNull("Link should not be null ", link);
+ }
+
+ /**
+ * Setting the circular relationship and also as a shared object.
+ *
+ * @throws Exception
+ */
+ public void testCircularReference4() throws Exception
+ {
+// try {Thread.sleep(10000); } catch (Exception e) {};
+ log.info("testCircularReference3() ...");
+ Link parent = new Link("parent");
+ Link child = new Link("child");
+ parent.setLink(child);
+ child.setLink(parent);
+
+ List<Link> list = new ArrayList<Link>();
+ list.add(parent);
+
+ cache1.attach("/list", list);
+ cache1.attach("/alias", list);
+
+ TestingUtil.sleepThread(100);
+ @SuppressWarnings("unchecked")
+ List<Link> list1 = (List<Link>) cache2.find("/list");
+ @SuppressWarnings("unchecked")
+ List<Link> list2 = (List<Link>) cache2.find("/alias");
+
+ assertEquals("parent", list1.get(0).getName());
+ assertEquals("child", list2.get(0).getLink().getName());
+ }
+
+ public void testCircularAndSharedReferences() throws Exception
+ {
+ log.info("testCircularAndSharedReferences() ...");
+ NodeManager pm_ = new NodeManager();
+
+ pm_.setRootNode("root");
+ pm_.addNode("root", "kanto");
+ pm_.addNode("root.kanto", "tokyo");
+ pm_.addNode("root.kanto", "kanagawa");
+
+ cache1.attach("/propagation", pm_);
+ assertEquals("kanagawa",
pm_.findNode("root.kanto.kanagawa").getNodeRDN());
+ pm_.addNode("root.kanto.tokyo", "hadanshita");
+ assertEquals("hadanshita",
pm_.findNode("root.kanto.tokyo.hadanshita").getNodeRDN());
+
+ NodeManager pm2_ = (NodeManager) cache2.find("/propagation");
+ assertEquals("kanagawa",
pm2_.findNode("root.kanto.kanagawa").getNodeRDN());
+ assertEquals("hadanshita",
pm2_.findNode("root.kanto.tokyo.hadanshita").getNodeRDN());
+
+/*
+ System.out.println("\n\n");
+ System.out.println("---------------------------------------------");
+ System.out.println("Initial pm state");
+ System.out.println("---------------------------------------------");
+ pm_.printNodes();
+
+ System.out.println("\n\n");
+ System.out.println("---------------------------------------------");
+ System.out.println("Initial cache content");
+ System.out.println(cache_.printDetails());
+ System.out.println("---------------------------------------------");
+*/
+ }
+
+
+
+}
Deleted:
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/ReplicatedObjectGraphTest.java
===================================================================
---
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/ReplicatedObjectGraphTest.java 2007-11-26
18:16:13 UTC (rev 4776)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/ReplicatedObjectGraphTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -1,231 +0,0 @@
-package org.jboss.cache.pojo;
-
-import static org.testng.AssertJUnit.assertEquals;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.config.Configuration.CacheMode;
-import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.pojo.test.Address;
-import org.jboss.cache.pojo.test.Person;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-/**
- * Test object graph handling in aop, e.g., circular reference, multiple reference, link,
etc.
- *
- * @author Ben Wang
- */
-
-@Test(groups = {"functional"})
-public class ReplicatedObjectGraphTest
-{
- Log log = LogFactory.getLog(ReplicatedObjectGraphTest.class);
- PojoCache cache1;
- PojoCache cache2;
-
-
- @BeforeMethod(alwaysRun = true)
- protected void setUp() throws Exception
- {
- log.info("setUp() ....");
- cache1 = createCache("CacheGroup");
- cache2 = createCache("CacheGroup");
- }
-
- @AfterMethod(alwaysRun = true)
- protected void tearDown() throws Exception
- {
- cache1.getCache().removeNode(Fqn.fromString("/"));
- cache1.stop();
- cache2.stop();
- }
-
- private PojoCache createCache(String name) throws Exception
- {
- boolean toStart = false;
- PojoCache tree =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
- tree.start();
- return tree;
- }
-
- // public void testDummy() {}
-
- protected Person createPerson(String name, int age)
- {
- Person p = new Person();
- p.setName(name);
- p.setAge(age);
- return p;
- }
-
- private void stage0() throws Exception
- {
- cache1.attach("/person/joe", createPerson("Joe Black", 31));
- Person joe = (Person) cache1.find("/person/joe");
- cache1.attach("/person/ben", createPerson("Ben Hogan", 51));
- Person ben = (Person) cache1.find("/person/ben");
-
- Address addr = new Address();
- addr.setStreet("123 Albert Ave.");
- addr.setCity("Sunnyvale");
- addr.setZip(94087);
- cache1.attach("/address", addr);
-
- // They share the sub-object: address
- joe.setAddress(addr);
- ben.setAddress(addr);
- assertEquals("Joe's address should still be valid ",
"Sunnyvale", joe.getAddress().getCity());
- assertEquals("Ben's address should still be valid ",
"Sunnyvale", ben.getAddress().getCity());
- }
-
- private void stage1() throws Exception
- {
- cache1.attach("/person/joe", createPerson("Joe Black", 31));
- Person joe = (Person) cache1.find("/person/joe");
- cache1.attach("/person/ben", createPerson("Ben Hogan", 51));
- Person ben = (Person) cache1.find("/person/ben");
-
- Address addr = new Address();
- addr.setStreet("123 Albert Ave.");
- addr.setCity("Sunnyvale");
- addr.setZip(94087);
-
- // They share the sub-object: address
- joe.setAddress(addr);
- ben.setAddress(addr);
- assertEquals("Joe's address should still be valid ",
"Sunnyvale", joe.getAddress().getCity());
- assertEquals("Ben's address should still be valid ",
"Sunnyvale", ben.getAddress().getCity());
- }
-
- private void stage2(PojoCache cache) throws Exception
- {
- //
- cache.detach("/person/joe");
- Person ben = (Person) cache.find("/person/ben");
- assertEquals("Ben's address should still be valid ",
"Sunnyvale", ben.getAddress().getCity());
- Address addr = ben.getAddress();
- addr.setCity("Santa Clara");
- assertEquals("Ben's address should be changed ", "Santa
Clara", ben.getAddress().getCity());
- }
-
- /**
- * Test whether repeated update on the ref count will change the replicated aop
instances
- *
- * @throws Exception
- */
- public void testCheckReplInstance() throws Exception
- {
- log.info("testCheckReplInstance() ...");
- stage0();
- TestingUtil.sleepThread(100);
- Person joe = (Person) cache1.find("/person/joe");
- Person ben = (Person) cache1.find("/person/ben");
- assertEquals("Ben and Joe's address should be the same ",
joe.getAddress().getCity(),
- ben.getAddress().getCity());
-
- Address joe1 = (Address) cache2.find("/address");
- assertEquals("Ben's address should not be changed ",
joe.getAddress().getCity(), joe1.getCity());
- ben = (Person) cache2.find("/person/ben");
- cache2.detach("/person/ben");
- Address joe2 = (Address) cache2.find("/address");
- assertEquals("Joe's reference should be the same.", joe1, joe2);
- }
-
- public void testRefCountCheckRepl() throws Exception
- {
- log.info("testRefCountCheckRepl() ...");
- stage1();
- TestingUtil.sleepThread(100);
- Person joe = (Person) cache1.find("/person/joe");
- Person ben = (Person) cache1.find("/person/ben");
- assertEquals("Ben and Joe's address should be the same ",
joe.getAddress().getCity(),
- ben.getAddress().getCity());
- TestingUtil.sleepThread(100);
- stage2(cache2);
- assertEquals("Ben's address should be changed on cache1 as well ",
"Santa Clara", ben.getAddress().getCity());
- cache2.detach("/person/ben");
- }
-
-
- public void testdetach1() throws Exception
- {
- log.info("testdetach1() ...");
- cache1.attach("/person/joe", createPerson("Joe Black", 31));
- Person joe = (Person) cache1.find("/person/joe");
- cache1.attach("/person/ben", createPerson("Ben Hogan", 51));
- Person ben = (Person) cache1.find("/person/ben");
-
- Address addr = new Address();
- addr.setStreet("123 Albert Ave.");
- addr.setCity("Sunnyvale");
- addr.setZip(94087);
-
- // They share the sub-object: address
- log.info("testMultipleReference(): set Joe address");
- joe.setAddress(addr);
- log.info("testMultipleReference(): set Ben address");
- ben.setAddress(addr);
-
- Address add1 = ((Person) cache2.find("/person/joe")).getAddress();
- Address add2 = ((Person) cache2.find("/person/ben")).getAddress();
- assertEquals(add1.getCity(), add2.getCity());
- addr.setCity("Santa Clara");
- assertEquals(add1.getCity(), add2.getCity());
-
- // Remove pojo joe will relocate the address field to ben's
- cache2.detach("/person/joe");
- add2 = ((Person) cache2.find("/person/ben")).getAddress();
-
- assertEquals("City ", "Santa Clara", add2.getCity());
- }
-
- public void testdetach2() throws Exception
- {
- log.info("testdetach2() ...");
- cache1.attach("/person/joe", createPerson("Joe Black", 31));
- Person joe = (Person) cache1.find("/person/joe");
- cache1.attach("/person/ben", createPerson("Ben Hogan", 51));
- Person ben = (Person) cache1.find("/person/ben");
- cache1.attach("/person/john", createPerson("John Daly", 41));
- Person john = (Person) cache1.find("/person/john");
-
- Address addr = new Address();
- addr.setStreet("123 Albert Ave.");
- addr.setCity("Sunnyvale");
- addr.setZip(94087);
-
- Address addr1 = new Address();
- addr1.setStreet("123 Albert Ave.");
- addr1.setCity("San Jose");
- addr1.setZip(94087);
-
- // They share the sub-object: address
- log.info("testMultipleReference(): set Joe address");
- joe.setAddress(addr);
- log.info("testMultipleReference(): set Ben address");
- ben.setAddress(addr);
- john.setAddress(addr);
-
- Address add1 = ((Person) cache2.find("/person/joe")).getAddress();
- Address add2 = ((Person) cache2.find("/person/ben")).getAddress();
- assertEquals(add1.getCity(), add2.getCity());
- addr.setCity("Santa Clara");
- assertEquals(add1.getCity(), add2.getCity());
-
- // Remove pojo joe will relocate the address field to ben's
- joe.setAddress(addr1);
- add2 = ((Person) cache2.find("/person/joe")).getAddress();
- assertEquals("City ", "San Jose", add2.getCity());
- add2 = ((Person) cache2.find("/person/ben")).getAddress();
- assertEquals("City ", "Santa Clara", add2.getCity());
- add2 = ((Person) cache2.find("/person/john")).getAddress();
- assertEquals("City ", "Santa Clara", add2.getCity());
- }
-
-
-
-}
-
Copied:
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/ReplicatedObjectGraphTest.java
(from rev 5129,
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/ReplicatedObjectGraphTest.java)
===================================================================
--- pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/ReplicatedObjectGraphTest.java
(rev 0)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/ReplicatedObjectGraphTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -0,0 +1,232 @@
+package org.jboss.cache.pojo;
+
+import static org.testng.AssertJUnit.assertEquals;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.pojo.test.Address;
+import org.jboss.cache.pojo.test.Person;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Test object graph handling in aop, e.g., circular reference, multiple reference, link,
etc.
+ *
+ * @author Ben Wang
+ */
+
+@Test(groups = {"functional"})
+public class ReplicatedObjectGraphTest
+{
+ Log log = LogFactory.getLog(ReplicatedObjectGraphTest.class);
+ PojoCache cache1;
+ PojoCache cache2;
+
+
+ @BeforeMethod(alwaysRun = true)
+ protected void setUp() throws Exception
+ {
+ log.info("setUp() ....");
+ cache1 = createCache("CacheGroup");
+ cache2 = createCache("CacheGroup");
+ }
+
+ @AfterMethod(alwaysRun = true)
+ protected void tearDown() throws Exception
+ {
+ cache1.getCache().removeNode(Fqn.fromString("/"));
+ cache1.stop();
+ cache2.stop();
+ }
+
+ private PojoCache createCache(String name) throws Exception
+ {
+ boolean toStart = false;
+ PojoCache tree =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
+ tree.start();
+ return tree;
+ }
+
+ // public void testDummy() {}
+
+ protected Person createPerson(String name, int age)
+ {
+ Person p = new Person();
+ p.setName(name);
+ p.setAge(age);
+ return p;
+ }
+
+ private void stage0() throws Exception
+ {
+ cache1.attach("/person/joe", createPerson("Joe Black", 31));
+ Person joe = (Person) cache1.find("/person/joe");
+ cache1.attach("/person/ben", createPerson("Ben Hogan", 51));
+ Person ben = (Person) cache1.find("/person/ben");
+
+ Address addr = new Address();
+ addr.setStreet("123 Albert Ave.");
+ addr.setCity("Sunnyvale");
+ addr.setZip(94087);
+ cache1.attach("/address", addr);
+
+ // They share the sub-object: address
+ joe.setAddress(addr);
+ ben.setAddress(addr);
+ assertEquals("Joe's address should still be valid ",
"Sunnyvale", joe.getAddress().getCity());
+ assertEquals("Ben's address should still be valid ",
"Sunnyvale", ben.getAddress().getCity());
+ }
+
+ private void stage1() throws Exception
+ {
+ cache1.attach("/person/joe", createPerson("Joe Black", 31));
+ Person joe = (Person) cache1.find("/person/joe");
+ cache1.attach("/person/ben", createPerson("Ben Hogan", 51));
+ Person ben = (Person) cache1.find("/person/ben");
+
+ Address addr = new Address();
+ addr.setStreet("123 Albert Ave.");
+ addr.setCity("Sunnyvale");
+ addr.setZip(94087);
+
+ // They share the sub-object: address
+ joe.setAddress(addr);
+ ben.setAddress(addr);
+ assertEquals("Joe's address should still be valid ",
"Sunnyvale", joe.getAddress().getCity());
+ assertEquals("Ben's address should still be valid ",
"Sunnyvale", ben.getAddress().getCity());
+ }
+
+ private void stage2(PojoCache cache) throws Exception
+ {
+ //
+ cache.detach("/person/joe");
+ Person ben = (Person) cache.find("/person/ben");
+ assertEquals("Ben's address should still be valid ",
"Sunnyvale", ben.getAddress().getCity());
+ Address addr = ben.getAddress();
+ addr.setCity("Santa Clara");
+ assertEquals("Ben's address should be changed ", "Santa
Clara", ben.getAddress().getCity());
+ }
+
+ /**
+ * Test whether repeated update on the ref count will change the replicated aop
instances
+ *
+ * @throws Exception
+ */
+ public void testCheckReplInstance() throws Exception
+ {
+ log.info("testCheckReplInstance() ...");
+ stage0();
+ TestingUtil.sleepThread(100);
+ Person joe = (Person) cache1.find("/person/joe");
+ Person ben = (Person) cache1.find("/person/ben");
+ assertEquals("Ben and Joe's address should be the same ",
joe.getAddress().getCity(),
+ ben.getAddress().getCity());
+
+ Address joe1 = (Address) cache2.find("/address");
+ assertEquals("Ben's address should not be changed ",
joe.getAddress().getCity(), joe1.getCity());
+ ben = (Person) cache2.find("/person/ben");
+ cache2.detach("/person/ben");
+ Address joe2 = (Address) cache2.find("/address");
+ assertEquals("Joe's reference should be the same.", joe1, joe2);
+ }
+
+ public void testRefCountCheckRepl() throws Exception
+ {
+ log.info("testRefCountCheckRepl() ...");
+ stage1();
+ TestingUtil.sleepThread(100);
+ Person joe = (Person) cache1.find("/person/joe");
+ Person ben = (Person) cache1.find("/person/ben");
+ assertEquals("Ben and Joe's address should be the same ",
joe.getAddress().getCity(),
+ ben.getAddress().getCity());
+ TestingUtil.sleepThread(100);
+ stage2(cache2);
+ assertEquals("Ben's address should be changed on cache1 as well ",
"Santa Clara", ben.getAddress().getCity());
+ cache2.detach("/person/ben");
+ }
+
+
+ public void testdetach1() throws Exception
+ {
+ log.info("testdetach1() ...");
+ cache1.attach("/person/joe", createPerson("Joe Black", 31));
+ Person joe = (Person) cache1.find("/person/joe");
+ cache1.attach("/person/ben", createPerson("Ben Hogan", 51));
+ Person ben = (Person) cache1.find("/person/ben");
+
+ Address addr = new Address();
+ addr.setStreet("123 Albert Ave.");
+ addr.setCity("Sunnyvale");
+ addr.setZip(94087);
+
+ // They share the sub-object: address
+ log.info("testMultipleReference(): set Joe address");
+ joe.setAddress(addr);
+ log.info("testMultipleReference(): set Ben address");
+ ben.setAddress(addr);
+
+ Address add1 = ((Person) cache2.find("/person/joe")).getAddress();
+ Address add2 = ((Person) cache2.find("/person/ben")).getAddress();
+ assertEquals(add1.getCity(), add2.getCity());
+ addr.setCity("Santa Clara");
+ assertEquals(add1.getCity(), add2.getCity());
+
+ // Remove pojo joe will relocate the address field to ben's
+ cache2.detach("/person/joe");
+ add2 = ((Person) cache2.find("/person/ben")).getAddress();
+
+ assertEquals("City ", "Santa Clara", add2.getCity());
+ }
+
+ public void testdetach2() throws Exception
+ {
+ log.info("testdetach2() ...");
+ cache1.attach("/person/joe", createPerson("Joe Black", 31));
+ Person joe = (Person) cache1.find("/person/joe");
+ cache1.attach("/person/ben", createPerson("Ben Hogan", 51));
+ Person ben = (Person) cache1.find("/person/ben");
+ cache1.attach("/person/john", createPerson("John Daly", 41));
+ Person john = (Person) cache1.find("/person/john");
+
+ Address addr = new Address();
+ addr.setStreet("123 Albert Ave.");
+ addr.setCity("Sunnyvale");
+ addr.setZip(94087);
+
+ Address addr1 = new Address();
+ addr1.setStreet("123 Albert Ave.");
+ addr1.setCity("San Jose");
+ addr1.setZip(94087);
+
+ // They share the sub-object: address
+ log.info("testMultipleReference(): set Joe address");
+ joe.setAddress(addr);
+ log.info("testMultipleReference(): set Ben address");
+ ben.setAddress(addr);
+ john.setAddress(addr);
+
+ Address add1 = ((Person) cache2.find("/person/joe")).getAddress();
+ Address add2 = ((Person) cache2.find("/person/ben")).getAddress();
+ assertEquals(add1.getCity(), add2.getCity());
+ addr.setCity("Santa Clara");
+ assertEquals(add1.getCity(), add2.getCity());
+
+ // Remove pojo joe will relocate the address field to ben's
+ joe.setAddress(addr1);
+ add2 = ((Person) cache2.find("/person/joe")).getAddress();
+ assertEquals("City ", "San Jose", add2.getCity());
+ add2 = ((Person) cache2.find("/person/ben")).getAddress();
+ assertEquals("City ", "Santa Clara", add2.getCity());
+ add2 = ((Person) cache2.find("/person/john")).getAddress();
+ assertEquals("City ", "Santa Clara", add2.getCity());
+ }
+
+
+
+}
+
Deleted: pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/ReplicatedTxTest.java
===================================================================
--- pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/ReplicatedTxTest.java 2007-11-26
18:16:13 UTC (rev 4776)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/ReplicatedTxTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -1,227 +0,0 @@
-package org.jboss.cache.pojo;
-
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.fail;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.transaction.NotSupportedException;
-import javax.transaction.RollbackException;
-import javax.transaction.SystemException;
-import javax.transaction.UserTransaction;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.config.Configuration.CacheMode;
-import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.pojo.test.Person;
-import org.jboss.cache.transaction.DummyTransactionManager;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-/**
- */
-
-@Test(groups = {"functional"})
-public class ReplicatedTxTest
-{
- Log log = LogFactory.getLog(ReplicatedTxTest.class);
- PojoCache cache, cache1;
- final String FACTORY = "org.jboss.cache.transaction.DummyContextFactory";
- DummyTransactionManager tx_mgr;
- Throwable t1_ex, t2_ex;
- long start = 0;
-
-
-
- @BeforeMethod(alwaysRun = true)
- protected void setUp() throws Exception
- {
- log.info("setUp() ....");
- boolean toStart = false;
- cache =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
- cache.start();
- cache1 =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
- cache1.start();
-
- System.setProperty(Context.INITIAL_CONTEXT_FACTORY, FACTORY);
-
- tx_mgr = DummyTransactionManager.getInstance();
- t1_ex = t2_ex = null;
- }
-
- @AfterMethod(alwaysRun = true)
- protected void tearDown() throws Exception
- {
- cache.stop();
- cache1.stop();
-
- DummyTransactionManager.destroy();
- }
-
-// public void testDummy() {}
-
- UserTransaction getTransaction() throws SystemException, NotSupportedException,
NamingException
- {
- Properties prop = new Properties();
- prop.put(Context.INITIAL_CONTEXT_FACTORY,
- "org.jboss.cache.transaction.DummyContextFactory");
- return (UserTransaction) new
InitialContext(prop).lookup("UserTransaction");
- }
-
- private Person createPerson(String id, String name, int age)
- {
- Person p = new Person();
- p.setName(name);
- p.setAge(age);
- cache.attach(id, p);
- return p;
- }
-
- public void testSimple() throws Exception
- {
- log.info("testSimple() ....");
- UserTransaction tx = getTransaction();
- tx.begin();
- Person p = createPerson("/person/test1", "Harald Gliebe", 32);
- tx.commit();
- tx.begin();
- p.setName("Benoit");
- tx.commit();
- Person p1 = (Person) cache1.find("/person/test1");
- assertEquals("Benoit", p.getName());
- assertEquals("Benoit", p1.getName());
- tx.begin();
- p1.setAge(61);
- tx.commit();
- assertEquals(61, p.getAge());
- assertEquals(61, p1.getAge());
- }
-
- public void testModification() throws Exception
- {
- UserTransaction tx = getTransaction();
- tx.begin();
- Person p = createPerson("/person/test2", "Harald", 32);
- p.setName("Harald Gliebe");
- tx.commit();
- Person p1 = (Person) cache1.find("/person/test2");
- tx.begin();
- p1.setName("Benoit");
- tx.commit();
- assertEquals(p.getName(), "Benoit");
- assertEquals(p1.getName(), "Benoit");
- tx.begin();
- p1.setName("Harald");
- tx.rollback();
- assertEquals(p.getName(), "Benoit");
- assertEquals(p1.getName(), "Benoit");
- }
-
- public void testConcurrentPuts() throws Exception
- {
- Thread t1 = new Thread()
- {
- public void run()
- {
- try
- {
- List<String> lang = ((Person)
cache.find("/person/test6")).getLanguages();
- UserTransaction tx = getTransaction();
- tx.begin();
- lang.add("German");
- TestingUtil.sleepThread(17000);
- tx.commit();
- }
- catch (RollbackException rollback)
- {
- ;
- }
- catch (Exception ex)
- {
- t1_ex = ex;
- }
- }
- };
-
- Thread t2 = new Thread()
- {
- public void run()
- {
- UserTransaction tx = null;
- try
- {
- TestingUtil.sleepThread(1000); // give Thread1 time to createPerson
- List<String> lang = ((Person)
cache.find("/person/test6")).getLanguages();
- tx = getTransaction();
- tx.begin();
- lang.add("English");
- tx.commit();
- }
- catch (RollbackException rollback)
- {
- ;
- }
- catch (Exception ex)
- {
- try
- {
- tx.rollback();
- } catch (SystemException e)
- {
- e.printStackTrace();
- t2_ex = e;
- }
- }
- }
- };
-
- Person p = createPerson("/person/test6", "p6", 50);
- List<String> lang = new ArrayList<String>();
- lang.add("German");
- p.setLanguages(lang);
-
- t1.start();
- t2.start();
-
- t1.join();
- t2.join();
-
- // t2 should rollback due to timeout while t2 should succeed
- if (t2_ex != null)
- fail("Thread1 failed: " + t2_ex);
- if (t1_ex != null)
- fail("Thread2 failed: " + t1_ex);
-
- int size = ((Person) cache.find("/person/test6")).getLanguages().size();
- assertEquals("number of languages should be 2, but is " + size + "
(" +
- ((Person) cache.find("/person/test6")).getLanguages().size() +
")",
- 2, size);
- size = ((Person) cache1.find("/person/test6")).getLanguages().size();
- assertEquals("number of languages should be 2, but is " + size + "
(" +
- ((Person) cache.find("/person/test6")).getLanguages().size() +
")",
- 2, size);
- }
-
- void log(String s)
- {
- long now;
- if (start == 0)
- start = System.currentTimeMillis();
- now = System.currentTimeMillis();
-
- System.out.println("[" + Thread.currentThread().getName() + "]
[" + (now - start) + "] " + s);
- }
-
-
-
-
-
-}
-
Copied: pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/ReplicatedTxTest.java (from
rev 5129, pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/ReplicatedTxTest.java)
===================================================================
--- pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/ReplicatedTxTest.java
(rev 0)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/ReplicatedTxTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -0,0 +1,228 @@
+package org.jboss.cache.pojo;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+import javax.transaction.UserTransaction;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.pojo.test.Person;
+import org.jboss.cache.transaction.DummyTransactionManager;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ */
+
+@Test(groups = {"functional"})
+public class ReplicatedTxTest
+{
+ Log log = LogFactory.getLog(ReplicatedTxTest.class);
+ PojoCache cache, cache1;
+ final String FACTORY = "org.jboss.cache.transaction.DummyContextFactory";
+ DummyTransactionManager tx_mgr;
+ Throwable t1_ex, t2_ex;
+ long start = 0;
+
+
+
+ @BeforeMethod(alwaysRun = true)
+ protected void setUp() throws Exception
+ {
+ log.info("setUp() ....");
+ boolean toStart = false;
+ cache =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
+ cache.start();
+ cache1 =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
+ cache1.start();
+
+ System.setProperty(Context.INITIAL_CONTEXT_FACTORY, FACTORY);
+
+ tx_mgr = DummyTransactionManager.getInstance();
+ t1_ex = t2_ex = null;
+ }
+
+ @AfterMethod(alwaysRun = true)
+ protected void tearDown() throws Exception
+ {
+ cache.stop();
+ cache1.stop();
+
+ DummyTransactionManager.destroy();
+ }
+
+// public void testDummy() {}
+
+ UserTransaction getTransaction() throws SystemException, NotSupportedException,
NamingException
+ {
+ Properties prop = new Properties();
+ prop.put(Context.INITIAL_CONTEXT_FACTORY,
+ "org.jboss.cache.transaction.DummyContextFactory");
+ return (UserTransaction) new
InitialContext(prop).lookup("UserTransaction");
+ }
+
+ private Person createPerson(String id, String name, int age)
+ {
+ Person p = new Person();
+ p.setName(name);
+ p.setAge(age);
+ cache.attach(id, p);
+ return p;
+ }
+
+ public void testSimple() throws Exception
+ {
+ log.info("testSimple() ....");
+ UserTransaction tx = getTransaction();
+ tx.begin();
+ Person p = createPerson("/person/test1", "Harald Gliebe", 32);
+ tx.commit();
+ tx.begin();
+ p.setName("Benoit");
+ tx.commit();
+ Person p1 = (Person) cache1.find("/person/test1");
+ assertEquals("Benoit", p.getName());
+ assertEquals("Benoit", p1.getName());
+ tx.begin();
+ p1.setAge(61);
+ tx.commit();
+ assertEquals(61, p.getAge());
+ assertEquals(61, p1.getAge());
+ }
+
+ public void testModification() throws Exception
+ {
+ UserTransaction tx = getTransaction();
+ tx.begin();
+ Person p = createPerson("/person/test2", "Harald", 32);
+ p.setName("Harald Gliebe");
+ tx.commit();
+ Person p1 = (Person) cache1.find("/person/test2");
+ tx.begin();
+ p1.setName("Benoit");
+ tx.commit();
+ assertEquals(p.getName(), "Benoit");
+ assertEquals(p1.getName(), "Benoit");
+ tx.begin();
+ p1.setName("Harald");
+ tx.rollback();
+ assertEquals(p.getName(), "Benoit");
+ assertEquals(p1.getName(), "Benoit");
+ }
+
+ public void testConcurrentPuts() throws Exception
+ {
+ Thread t1 = new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ List<String> lang = ((Person)
cache.find("/person/test6")).getLanguages();
+ UserTransaction tx = getTransaction();
+ tx.begin();
+ lang.add("German");
+ TestingUtil.sleepThread(17000);
+ tx.commit();
+ }
+ catch (RollbackException rollback)
+ {
+ ;
+ }
+ catch (Exception ex)
+ {
+ t1_ex = ex;
+ }
+ }
+ };
+
+ Thread t2 = new Thread()
+ {
+ public void run()
+ {
+ UserTransaction tx = null;
+ try
+ {
+ TestingUtil.sleepThread(1000); // give Thread1 time to createPerson
+ List<String> lang = ((Person)
cache.find("/person/test6")).getLanguages();
+ tx = getTransaction();
+ tx.begin();
+ lang.add("English");
+ tx.commit();
+ }
+ catch (RollbackException rollback)
+ {
+ ;
+ }
+ catch (Exception ex)
+ {
+ try
+ {
+ tx.rollback();
+ } catch (SystemException e)
+ {
+ e.printStackTrace();
+ t2_ex = e;
+ }
+ }
+ }
+ };
+
+ Person p = createPerson("/person/test6", "p6", 50);
+ List<String> lang = new ArrayList<String>();
+ lang.add("German");
+ p.setLanguages(lang);
+
+ t1.start();
+ t2.start();
+
+ t1.join();
+ t2.join();
+
+ // t2 should rollback due to timeout while t2 should succeed
+ if (t2_ex != null)
+ fail("Thread1 failed: " + t2_ex);
+ if (t1_ex != null)
+ fail("Thread2 failed: " + t1_ex);
+
+ int size = ((Person) cache.find("/person/test6")).getLanguages().size();
+ assertEquals("number of languages should be 2, but is " + size + "
(" +
+ ((Person) cache.find("/person/test6")).getLanguages().size() +
")",
+ 2, size);
+ size = ((Person) cache1.find("/person/test6")).getLanguages().size();
+ assertEquals("number of languages should be 2, but is " + size + "
(" +
+ ((Person) cache.find("/person/test6")).getLanguages().size() +
")",
+ 2, size);
+ }
+
+ void log(String s)
+ {
+ long now;
+ if (start == 0)
+ start = System.currentTimeMillis();
+ now = System.currentTimeMillis();
+
+ System.out.println("[" + Thread.currentThread().getName() + "]
[" + (now - start) + "] " + s);
+ }
+
+
+
+
+
+}
+
Deleted: pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/TestingUtil.java
===================================================================
--- pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/TestingUtil.java 2007-11-26
18:16:13 UTC (rev 4776)
+++ pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/TestingUtil.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -1,139 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at
gnu.org.
- */
-
-package org.jboss.cache.pojo;
-
-import org.jboss.cache.CacheImpl;
-import org.jgroups.Address;
-
-import java.util.List;
-
-/**
- * Utilities for unit testing JBossCache.
- *
- * @author <a href="mailto://brian.stansberry@jboss.com">Brian
Stansberry</a>
- * @version $Revision$
- */
-public class TestingUtil
-{
-
- /**
- * @param caches caches which must all have consistent views
- * @param timeout max number of ms to loop
- * @throws RuntimeException if <code>timeout</code> ms have elapse
without
- * all caches having the same number of members.
- */
- public static void blockUntilViewsReceived(PojoCache[] caches, long timeout)
- {
- long failTime = System.currentTimeMillis() + timeout;
-
- while (System.currentTimeMillis() < failTime)
- {
- org.jboss.cache.pojo.TestingUtil.sleepThread(100);
- if (org.jboss.cache.pojo.TestingUtil.areCacheViewsComplete(caches))
- return;
- }
-
- throw new RuntimeException("timed out before caches had complete
views");
- }
-
- /**
- */
- public static void blockUntilViewReceived(PojoCache cache, int groupSize, long
timeout)
- {
- long failTime = System.currentTimeMillis() + timeout;
-
- CacheImpl<Object, Object> tcache = (CacheImpl<Object, Object>)
cache.getCache();
- while (System.currentTimeMillis() < failTime)
- {
- org.jboss.cache.pojo.TestingUtil.sleepThread(100);
- if (org.jboss.cache.pojo.TestingUtil.isCacheViewComplete(tcache, groupSize))
- return;
- }
-
- throw new RuntimeException("timed out before caches had complete
views");
- }
-
- /**
- * Checks each cache to see if the number of elements in the array
- * returned by {@link org.jboss.cache.CacheImpl#getMembers()} matches the size of
- * the <code>caches</code> parameter.
- *
- * @param caches caches that should form a View
- * @return <code>true</code> if all caches have
- * <code>caches.length</code> members; false otherwise
- * @throws IllegalStateException if any of the caches have MORE view
- * members than caches.length
- */
- public static boolean areCacheViewsComplete(PojoCache[] caches)
- {
- int memberCount = caches.length;
-
- for (int i = 0; i < memberCount; i++)
- {
- CacheImpl<Object, Object> cache = (CacheImpl<Object, Object>)
caches[i].getCache();
- return org.jboss.cache.pojo.TestingUtil.isCacheViewComplete(cache,
memberCount);
- }
-
- return true;
- }
-
- /**
- * FIXME Comment this
- *
- * @param cache
- * @param memberCount
- */
- public static boolean isCacheViewComplete(CacheImpl<Object, Object> cache, int
memberCount)
- {
- List<Address> members = cache.getMembers();
- if (members == null || memberCount > members.size())
- {
- return false;
- }
- else if (memberCount < members.size())
- {
- // This is an exceptional condition
- StringBuffer sb = new StringBuffer("Cache at address ");
- sb.append(cache.getLocalAddress());
- sb.append(" had ");
- sb.append(members.size());
- sb.append(" members; expecting ");
- sb.append(memberCount);
- sb.append(". Members were (");
- for (int j = 0; j < members.size(); j++)
- {
- if (j > 0)
- sb.append(", ");
- sb.append(members.get(j));
- }
- sb.append(')');
-
- throw new IllegalStateException(sb.toString());
- }
-
- return true;
- }
-
-
- /**
- * Puts the current thread to sleep for the desired number of ms, suppressing
- * any exceptions.
- *
- * @param sleeptime number of ms to sleep
- */
- public static void sleepThread(long sleeptime)
- {
- try
- {
- Thread.sleep(sleeptime);
- }
- catch (InterruptedException ie)
- {
- }
- }
-}
Deleted:
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/collection/ReplicatedSyncListTest.java
===================================================================
---
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/collection/ReplicatedSyncListTest.java 2007-11-26
18:16:13 UTC (rev 4776)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/collection/ReplicatedSyncListTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -1,319 +0,0 @@
-package org.jboss.cache.pojo.collection;
-
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertTrue;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.ListIterator;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.aop.proxy.ClassProxy;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.config.Configuration.CacheMode;
-import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.pojo.PojoCache;
-import org.jboss.cache.pojo.PojoCacheAlreadyDetachedException;
-import org.jboss.cache.pojo.PojoCacheFactory;
-import org.jboss.cache.pojo.test.Address;
-import org.jboss.cache.pojo.test.Person;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-/**
- * Test object graph handling in aop, e.g., circular reference, multiple reference, link,
etc.
- *
- * @author Ben Wang
- */
-
-@Test(groups = {"functional"})
-public class ReplicatedSyncListTest
-{
- Log log = LogFactory.getLog(ReplicatedSyncListTest.class);
- PojoCache cache1;
- PojoCache cache2;
-
-
- @BeforeMethod(alwaysRun = true)
- protected void setUp() throws Exception
- {
- log.info("setUp() ....");
- cache1 = createCache("CacheGroup");
- cache2 = createCache("CacheGroup");
- }
-
- @AfterMethod(alwaysRun = true)
- protected void tearDown() throws Exception
- {
- cache1.getCache().removeNode(Fqn.fromString("/"));
- cache1.stop();
- cache2.stop();
- }
-
- private PojoCache createCache(String name) throws Exception
- {
- boolean toStart = false;
- PojoCache cache =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
- cache.start();
- return cache;
- }
-
-// public void testDummy() {}
-
-
- protected Person createPerson(String name, int age)
- {
- Person p = new Person();
- p.setName(name);
- p.setAge(age);
- return p;
- }
-
- /**
- * Test attachment and then detachment and attachment.
- *
- * @throws Exception
- */
- @SuppressWarnings("unchecked")
- public void testAttachDetach() throws Exception
- {
- log.info("testAttachDetach() ....");
- List<Address> list1 = new ArrayList<Address>();
- Address addr = new Address();
- addr.setCity("San Jose");
- addr.setZip(95123);
- list1.add(addr);
-
- Address addr2 = new Address();
- addr2.setCity("Santa Clara");
- addr2.setZip(95131);
-
- Address addr3 = new Address();
- addr3.setCity("Sunnyvale");
- addr3.setZip(94086);
-
- // Pure list
- cache1.attach("/list", list1);
- list1 = (List<Address>) cache1.find("/list");
- list1.add(addr2);
- // The return value is the original reference.
- list1 = (List<Address>) cache1.detach("/list");
- assertEquals("Detached list should still be", 2, list1.size());
- list1.add(addr3);
- cache1.attach("/list", list1);
-
- List list2 = (List) cache2.find("/list");
- assertTrue("List size should not be 0 ", (list2.size() != 0));
- assertEquals("Both list values should be equal ", list1.get(0).getZip(),
- ((Address) list2.get(0)).getZip());
- }
-
- @SuppressWarnings("unchecked")
- public void testRemoteDetach() throws Exception
- {
- List<Object> list = new ArrayList<Object>();
- Address addr = new Address();
- addr.setCity("San Jose");
- addr.setZip(95123);
- list.add(addr);
-
- Address addr2 = new Address();
- addr2.setCity("Santa Clara");
- addr2.setZip(95131);
-
- cache1.attach("/list", list);
- list = (List<Object>) cache2.find("/list");
- cache1.detach("/list");
-
- boolean pass = false;
- try
- {
- list.add(addr);
- }
- catch (PojoCacheAlreadyDetachedException e)
- {
- pass = true;
- }
-
- assertTrue("Expected PojoCacheAlreadyDetachedExcpetion!", pass);
- }
-
- /**
- * Two different keys share same list.
- *
- * @throws Exception
- */
- @SuppressWarnings("unchecked")
- public void testRelationshipWithSharedList1() throws Exception
- {
- log.info("testRelationshipWithList() ....");
- List<Address> list1 = new ArrayList<Address>();
- Address addr = new Address();
- addr.setCity("San Jose");
- addr.setZip(95123);
- list1.add(addr);
-
- // Pure list
- cache1.attach("/list", list1);
- // We specifically need to use Proxy otherwise it won't work with multiple
references
- list1 = (List<Address>) cache1.find("/list");
- cache1.attach("/alias", list1);
-
- List list2 = (List) cache1.find("/alias");
- Address add1 = (Address) list2.get(0);
- assertNotNull("Address should not be null", add1);
- assertEquals("Zip ", 95123, add1.getZip());
-
- list1 = (List<Address>) cache2.find("/list");
- list2 = (List) cache2.find("/alias");
- assertTrue("List size should not be 0 ", (list2.size() != 0));
- assertEquals("Both lists should be equal ", list1, list2);
- assertEquals("Both list values should be equal ", list1.get(0),
list2.get(0));
- }
-
- /**
- * Shared object between two list item.
- *
- * @throws Exception
- */
- public void testRelationshipWithSharedList2() throws Exception
- {
- log.info("testRelationshipWithList2() ....");
- // 2 lists with shared objects
- List<Address> list1 = new ArrayList<Address>();
- Address addr = new Address();
- addr.setCity("San Jose");
- addr.setZip(95123);
- list1.add(addr);
-
- List<Address> list2 = new ArrayList<Address>();
- list2.add(addr);
-
- cache1.attach("/list1", list1);
- cache1.attach("/list2", list2);
- @SuppressWarnings("unchecked")
- Address add2 = ((List<Address>) cache2.find("/list2")).get(0);
- @SuppressWarnings("unchecked")
- Address add1 = ((List<Address>) cache2.find("/list1")).get(0);
- assertEquals("Address should be the same", add1, add2);
- assertEquals("Both shared object should be equal ", add2.getZip(),
add1.getZip());
- }
-
- /**
- * Shared object between regular POJO and List item.
- *
- * @throws Exception
- */
- public void testRelationshipWithSharedList3() throws Exception
- {
- log.info("testRelationshipWithList3() ....");
- // 2 lists with shared objects
- List<Address> list1 = new ArrayList<Address>();
- Address addr = new Address();
- addr.setCity("San Jose");
- addr.setZip(95123);
- list1.add(addr);
-
- List<Address> list2 = new ArrayList<Address>();
- list2.add(addr);
-
- cache1.attach("/address", addr);
- cache1.attach("/list1", list1);
- @SuppressWarnings("unchecked")
- Address add1 = ((List<Address>) cache2.find("/list1")).get(0);
- Address add2 = (Address) cache2.find("/address");
- assertEquals("Address should be the same", add1, add2);
- assertEquals("Both shared object should be equal ", 95123,
add1.getZip());
- }
-
- @SuppressWarnings("unchecked")
- public void testNullWithSharedList1() throws Exception
- {
- log.info("testNullWithSharedList1() ....");
- List<String> list1 = new ArrayList<String>();
- list1.add("element 0");
- list1.add(null); // element 1
- list1.add("element 2");
- list1.add(null); // element 3
-
- // Pure set
- cache1.attach("/list", list1);
- // We specifically need to use Proxy otherwise it won't work with multiple
references
- list1 = (List<String>) cache1.find("/list");
- cache1.attach("/alias", list1);
-
- List<String> list2 = (List) cache1.find("/alias");
-
- list1 = (List<String>) cache2.find("/list");
- list2 = (List<String>) cache2.find("/alias");
- assertTrue("List size should not be 0 ", (list2.size() != 0));
- assertEquals("Both listss should be equal ", list1, list2);
-
- Object a1[] = list1.toArray();
- Object a2[] = list2.toArray();
- assertTrue("element 1 is null", (a1[1] == null));
- assertTrue("element 1 is null", (a2[1] == null));
- assertTrue("element 3 is null", (a1[3] == null));
- assertTrue("element 3 is null", (a2[3] == null));
-
- assertTrue("contains test for null value", list1.contains(null));
- assertTrue("contains test for null value", list2.contains(null));
-
- assertTrue("index of null ", list2.indexOf(null) == 1);
- assertTrue("last index of null ", list2.lastIndexOf(null) == 3);
-
- list1.set(0, null); // set first element to null
- assertTrue("set first item to null", list2.get(0) == null);
- list1.set(0, "element 0");
- assertTrue("set first item to 'element 0'",
list2.get(0).equals("element 0"));
-
-
- ListIterator<String> listIter = list1.listIterator();
- assertTrue("listiter has next", listIter.hasNext());
- assertTrue("listiter 1st element is 'element 0'",
listIter.next().equals("element 0"));
- assertTrue("listiter has next", listIter.hasNext());
- assertTrue("listiter 2nd element is null", listIter.next() == null);
- listIter.remove();
-
- assertTrue("2nd element should be 'element 2'",
list2.get(1).equals("element 2"));
-
- }
-
- @SuppressWarnings("unchecked")
- public void testRecursion1() throws Exception
- {
- List<Object> list = new ArrayList<Object>();
- list.add("1");
- list.add("2");
- cache1.attach("list", list);
-
- list = (List<Object>) cache1.find("list");
- list.add(list);
-
- assertEquals("size ", 3, list.size());
- List l2 = (List) list.get(2);
- assertTrue("Instance of AopProxy", l2 instanceof ClassProxy);
-// assertEquals("ClassProxy instance", list, l2);
- }
-
- @SuppressWarnings("unchecked")
- public void testRecursion2() throws Exception
- {
- List<Object> list = new ArrayList<Object>();
- list.add("1");
- list.add("2");
- list.add(list);
-
- cache1.attach("list", list);
-
- list = (List<Object>) cache1.find("list");
- list.toString();
- }
-
-
-
-}
-
Copied:
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/collection/ReplicatedSyncListTest.java
(from rev 5139,
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/collection/ReplicatedSyncListTest.java)
===================================================================
---
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/collection/ReplicatedSyncListTest.java
(rev 0)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/collection/ReplicatedSyncListTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -0,0 +1,319 @@
+package org.jboss.cache.pojo.collection;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.aop.proxy.ClassProxy;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.pojo.PojoCache;
+import org.jboss.cache.pojo.PojoCacheAlreadyDetachedException;
+import org.jboss.cache.pojo.PojoCacheFactory;
+import org.jboss.cache.pojo.test.Address;
+import org.jboss.cache.pojo.test.Person;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Test object graph handling in aop, e.g., circular reference, multiple reference, link,
etc.
+ *
+ * @author Ben Wang
+ */
+
+@Test(groups = {"functional"}, enabled=false)
+public class ReplicatedSyncListTest
+{
+ Log log = LogFactory.getLog(ReplicatedSyncListTest.class);
+ PojoCache cache1;
+ PojoCache cache2;
+
+
+ @BeforeMethod(alwaysRun = true)
+ protected void setUp() throws Exception
+ {
+ log.info("setUp() ....");
+ cache1 = createCache("CacheGroup");
+ cache2 = createCache("CacheGroup");
+ }
+
+ @AfterMethod(alwaysRun = true)
+ protected void tearDown() throws Exception
+ {
+ //cache1.getCache().removeNode(Fqn.fromString("/"));
+ cache1.stop();
+ cache2.stop();
+ }
+
+ private PojoCache createCache(String name) throws Exception
+ {
+ boolean toStart = false;
+ PojoCache cache =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
+ cache.start();
+ return cache;
+ }
+
+// public void testDummy() {}
+
+
+ protected Person createPerson(String name, int age)
+ {
+ Person p = new Person();
+ p.setName(name);
+ p.setAge(age);
+ return p;
+ }
+
+ /**
+ * Test attachment and then detachment and attachment.
+ *
+ * @throws Exception
+ */
+ @SuppressWarnings("unchecked")
+ public void testAttachDetach() throws Exception
+ {
+ log.info("testAttachDetach() ....");
+ List<Address> list1 = new ArrayList<Address>();
+ Address addr = new Address();
+ addr.setCity("San Jose");
+ addr.setZip(95123);
+ list1.add(addr);
+
+ Address addr2 = new Address();
+ addr2.setCity("Santa Clara");
+ addr2.setZip(95131);
+
+ Address addr3 = new Address();
+ addr3.setCity("Sunnyvale");
+ addr3.setZip(94086);
+
+ // Pure list
+ cache1.attach("/list", list1);
+ list1 = (List<Address>) cache1.find("/list");
+ list1.add(addr2);
+ // The return value is the original reference.
+ list1 = (List<Address>) cache1.detach("/list");
+ assertEquals("Detached list should still be", 2, list1.size());
+ list1.add(addr3);
+ cache1.attach("/list", list1);
+
+ List list2 = (List) cache2.find("/list");
+ assertTrue("List size should not be 0 ", (list2.size() != 0));
+ assertEquals("Both list values should be equal ", list1.get(0).getZip(),
+ ((Address) list2.get(0)).getZip());
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testRemoteDetach() throws Exception
+ {
+ List<Object> list = new ArrayList<Object>();
+ Address addr = new Address();
+ addr.setCity("San Jose");
+ addr.setZip(95123);
+ list.add(addr);
+
+ Address addr2 = new Address();
+ addr2.setCity("Santa Clara");
+ addr2.setZip(95131);
+
+ cache1.attach("/list", list);
+ list = (List<Object>) cache2.find("/list");
+ cache1.detach("/list");
+
+ boolean pass = false;
+ try
+ {
+ list.add(addr);
+ }
+ catch (PojoCacheAlreadyDetachedException e)
+ {
+ pass = true;
+ }
+
+ assertTrue("Expected PojoCacheAlreadyDetachedExcpetion!", pass);
+ }
+
+ /**
+ * Two different keys share same list.
+ *
+ * @throws Exception
+ */
+ @SuppressWarnings("unchecked")
+ public void testRelationshipWithSharedList1() throws Exception
+ {
+ log.info("testRelationshipWithList() ....");
+ List<Address> list1 = new ArrayList<Address>();
+ Address addr = new Address();
+ addr.setCity("San Jose");
+ addr.setZip(95123);
+ list1.add(addr);
+
+ // Pure list
+ cache1.attach("/list", list1);
+ // We specifically need to use Proxy otherwise it won't work with multiple
references
+ list1 = (List<Address>) cache1.find("/list");
+ cache1.attach("/alias", list1);
+
+ List list2 = (List) cache1.find("/alias");
+ Address add1 = (Address) list2.get(0);
+ assertNotNull("Address should not be null", add1);
+ assertEquals("Zip ", 95123, add1.getZip());
+
+ list1 = (List<Address>) cache2.find("/list");
+ list2 = (List) cache2.find("/alias");
+ assertTrue("List size should not be 0 ", (list2.size() != 0));
+ assertEquals("Both lists should be equal ", list1, list2);
+ assertEquals("Both list values should be equal ", list1.get(0),
list2.get(0));
+ }
+
+ /**
+ * Shared object between two list item.
+ *
+ * @throws Exception
+ */
+ public void testRelationshipWithSharedList2() throws Exception
+ {
+ log.info("testRelationshipWithList2() ....");
+ // 2 lists with shared objects
+ List<Address> list1 = new ArrayList<Address>();
+ Address addr = new Address();
+ addr.setCity("San Jose");
+ addr.setZip(95123);
+ list1.add(addr);
+
+ List<Address> list2 = new ArrayList<Address>();
+ list2.add(addr);
+
+ cache1.attach("/list1", list1);
+ cache1.attach("/list2", list2);
+ @SuppressWarnings("unchecked")
+ Address add2 = ((List<Address>) cache2.find("/list2")).get(0);
+ @SuppressWarnings("unchecked")
+ Address add1 = ((List<Address>) cache2.find("/list1")).get(0);
+ assertEquals("Address should be the same", add1, add2);
+ assertEquals("Both shared object should be equal ", add2.getZip(),
add1.getZip());
+ }
+
+ /**
+ * Shared object between regular POJO and List item.
+ *
+ * @throws Exception
+ */
+ public void testRelationshipWithSharedList3() throws Exception
+ {
+ log.info("testRelationshipWithList3() ....");
+ // 2 lists with shared objects
+ List<Address> list1 = new ArrayList<Address>();
+ Address addr = new Address();
+ addr.setCity("San Jose");
+ addr.setZip(95123);
+ list1.add(addr);
+
+ List<Address> list2 = new ArrayList<Address>();
+ list2.add(addr);
+
+ cache1.attach("/address", addr);
+ cache1.attach("/list1", list1);
+ @SuppressWarnings("unchecked")
+ Address add1 = ((List<Address>) cache2.find("/list1")).get(0);
+ Address add2 = (Address) cache2.find("/address");
+ assertEquals("Address should be the same", add1, add2);
+ assertEquals("Both shared object should be equal ", 95123,
add1.getZip());
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testNullWithSharedList1() throws Exception
+ {
+ log.info("testNullWithSharedList1() ....");
+ List<String> list1 = new ArrayList<String>();
+ list1.add("element 0");
+ list1.add(null); // element 1
+ list1.add("element 2");
+ list1.add(null); // element 3
+
+ // Pure set
+ cache1.attach("/list", list1);
+ // We specifically need to use Proxy otherwise it won't work with multiple
references
+ list1 = (List<String>) cache1.find("/list");
+ cache1.attach("/alias", list1);
+
+ List<String> list2 = (List) cache1.find("/alias");
+
+ list1 = (List<String>) cache2.find("/list");
+ list2 = (List<String>) cache2.find("/alias");
+ assertTrue("List size should not be 0 ", (list2.size() != 0));
+ assertEquals("Both listss should be equal ", list1, list2);
+
+ Object a1[] = list1.toArray();
+ Object a2[] = list2.toArray();
+ assertTrue("element 1 is null", (a1[1] == null));
+ assertTrue("element 1 is null", (a2[1] == null));
+ assertTrue("element 3 is null", (a1[3] == null));
+ assertTrue("element 3 is null", (a2[3] == null));
+
+ assertTrue("contains test for null value", list1.contains(null));
+ assertTrue("contains test for null value", list2.contains(null));
+
+ assertTrue("index of null ", list2.indexOf(null) == 1);
+ assertTrue("last index of null ", list2.lastIndexOf(null) == 3);
+
+ list1.set(0, null); // set first element to null
+ assertTrue("set first item to null", list2.get(0) == null);
+ list1.set(0, "element 0");
+ assertTrue("set first item to 'element 0'",
list2.get(0).equals("element 0"));
+
+
+ ListIterator<String> listIter = list1.listIterator();
+ assertTrue("listiter has next", listIter.hasNext());
+ assertTrue("listiter 1st element is 'element 0'",
listIter.next().equals("element 0"));
+ assertTrue("listiter has next", listIter.hasNext());
+ assertTrue("listiter 2nd element is null", listIter.next() == null);
+ listIter.remove();
+
+ assertTrue("2nd element should be 'element 2'",
list2.get(1).equals("element 2"));
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testRecursion1() throws Exception
+ {
+ List<Object> list = new ArrayList<Object>();
+ list.add("1");
+ list.add("2");
+ cache1.attach("list", list);
+
+ list = (List<Object>) cache1.find("list");
+ list.add(list);
+
+ assertEquals("size ", 3, list.size());
+ List l2 = (List) list.get(2);
+ assertTrue("Instance of AopProxy", l2 instanceof ClassProxy);
+// assertEquals("ClassProxy instance", list, l2);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testRecursion2() throws Exception
+ {
+ List<Object> list = new ArrayList<Object>();
+ list.add("1");
+ list.add("2");
+ list.add(list);
+
+ cache1.attach("list", list);
+
+ list = (List<Object>) cache1.find("list");
+ list.toString();
+ }
+
+
+
+}
+
Deleted: pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/jmx/NotificationTest.java
===================================================================
---
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/jmx/NotificationTest.java 2007-11-26
18:16:13 UTC (rev 4776)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/jmx/NotificationTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -1,62 +0,0 @@
-package org.jboss.cache.pojo.jmx;
-
-import javax.management.ObjectName;
-
-import org.jboss.cache.CacheImpl;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.pojo.PojoCache;
-import org.jboss.cache.pojo.PojoCacheFactory;
-import org.jboss.cache.pojo.impl.PojoCacheImpl;
-import org.testng.annotations.Test;
-
-/**
- * Functional tests for CacheJmxWrapper broadcast of cache event notifications
- *
- * @author Jerry Gauthier
- * @version $Id$
- */
-@Test(groups = {"functional"})
-public class NotificationTest extends org.jboss.cache.jmx.NotificationTest
-{
- private PojoCache pojoCache;
-
-
-
- @Override
- protected Object createCacheAndJmxWrapper() throws Exception
- {
- pojoCache = createCache(CLUSTER_NAME);
- cache = (CacheImpl<Object, Object>) pojoCache.getCache();
- return new PojoCacheJmxWrapper(pojoCache);
- }
-
- @Override
- protected void destroyCache()
- {
- if (pojoCache != null)
- {
- // stop the cache before the listener is unregistered
- //cache1.stop();
- pojoCache.destroy();
- pojoCache = null;
- cache = null;
- }
- }
-
- protected ObjectName getWrapperObjectName() throws Exception
- {
- return new ObjectName(JmxUtil.PREFIX + CLUSTER_NAME);
- }
-
- protected PojoCacheImpl createCache(String clusterName) throws Exception
- {
- Configuration config = createConfiguration(clusterName);
-
- PojoCacheImpl cache = (PojoCacheImpl) PojoCacheFactory.createCache(config, false);
-
- cache.create();
- // start the cache after the listener has been registered
- //cache.start();
- return cache;
- }
-}
\ No newline at end of file
Copied: pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/jmx/NotificationTest.java
(from rev 5129,
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/jmx/NotificationTest.java)
===================================================================
--- pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/jmx/NotificationTest.java
(rev 0)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/jmx/NotificationTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -0,0 +1,62 @@
+package org.jboss.cache.pojo.jmx;
+
+import javax.management.ObjectName;
+
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.pojo.PojoCache;
+import org.jboss.cache.pojo.PojoCacheFactory;
+import org.jboss.cache.pojo.impl.PojoCacheImpl;
+import org.testng.annotations.Test;
+
+/**
+ * Functional tests for CacheJmxWrapper broadcast of cache event notifications
+ *
+ * @author Jerry Gauthier
+ * @version $Id$
+ */
+@Test(groups = {"functional"})
+public class NotificationTest extends org.jboss.cache.jmx.NotificationTest
+{
+ private PojoCache pojoCache;
+
+
+
+ @Override
+ protected Object createCacheAndJmxWrapper() throws Exception
+ {
+ pojoCache = createCache(CLUSTER_NAME);
+ cache = (CacheSPI<Object, Object>)pojoCache.getCache();
+ return new PojoCacheJmxWrapper(pojoCache);
+ }
+
+ @Override
+ protected void destroyCache()
+ {
+ if (pojoCache != null)
+ {
+ // stop the cache before the listener is unregistered
+ //cache1.stop();
+ pojoCache.destroy();
+ pojoCache = null;
+ cache = null;
+ }
+ }
+
+ protected ObjectName getWrapperObjectName() throws Exception
+ {
+ return new ObjectName(JmxUtil.PREFIX + CLUSTER_NAME);
+ }
+
+ protected PojoCacheImpl createCache(String clusterName) throws Exception
+ {
+ Configuration config = createConfiguration(clusterName);
+
+ PojoCacheImpl cache = (PojoCacheImpl) PojoCacheFactory.createCache(config, false);
+
+ cache.create();
+ // start the cache after the listener has been registered
+ //cache.start();
+ return cache;
+ }
+}
\ No newline at end of file
Deleted:
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/memory/ReplicatedTest.java
===================================================================
---
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/memory/ReplicatedTest.java 2007-11-26
18:16:13 UTC (rev 4776)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/memory/ReplicatedTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -1,186 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at
gnu.org.
- */
-
-package org.jboss.cache.pojo.memory;
-
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.fail;
-
-import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.config.Configuration.CacheMode;
-import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.pojo.PojoCache;
-import org.jboss.cache.pojo.PojoCacheFactory;
-import org.jboss.cache.pojo.TestingUtil;
-import org.jboss.cache.pojo.test.Address;
-import org.jboss.cache.pojo.test.Person;
-import org.jboss.cache.pojo.test.SerializedAddress;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-/**
- * @author Ben Wang
- */
-
-@Test(groups = {"functional"})
-public class ReplicatedTest
-{
- Log log_ = LogFactory.getLog(ReplicatedTest.class);
- PojoCache cache_;
- PojoCache cache1_;
-
-
- @BeforeMethod(alwaysRun = true)
- protected void setUp() throws Exception
- {
- boolean toStart = false;
- cache_ =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
- cache_.start();
- cache1_ =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
- cache1_.start();
- }
-
- @AfterMethod(alwaysRun = true)
- protected void tearDown() throws Exception
- {
- cache_.stop();
- cache1_.stop();
- }
-
-// public void testDummy() {}
-
- /**
- * Test replication with classloaders.
- *
- * @throws Exception
- */
- public void testCLLeakageBasic() throws Exception
- {
- SerializedAddress add = new SerializedAddress();
- add.setCity("Taipei");
-
- ClassLoader cla = getClassLoader();
- WeakReference<ClassLoader> refa = new WeakReference<ClassLoader>(cla);
- cache_.getCache().getRegion(new Fqn<String>("/aop"),
true).registerContextClassLoader(cla);
- ClassLoader clb = getClassLoader();
- WeakReference<ClassLoader> refb = new WeakReference<ClassLoader>(clb);
- cache_.getCache().getRegion(new Fqn<String>("/aop"),
true).registerContextClassLoader(clb);
-
- Fqn<String> fqn = new Fqn<String>("/aop");
- cache_.getCache().put(new Fqn<String>("/aop"), "add",
add);
-
- TestingUtil.sleepThread(100);
- try
- {
- Object ben = cache1_.getCache().get(fqn, "add");
- assertEquals(add.toString(), ben.toString());
- ben = null;
- }
- catch (Exception ex)
- {
- fail("Test fails with exception " + ex);
- }
-
- cache_.getCache().remove(fqn, "add");
-
- ClassLoader clc = getClassLoader();
- cla = null;
- clb = null;
- cache_.getCache().getRegion(new Fqn<String>("/aop"),
true).registerContextClassLoader(clc);
- cache1_.getCache().getRegion(new Fqn<String>("/aop"),
true).registerContextClassLoader(clc);
- System.gc(); // force gc
- Thread.sleep(1000);
- assertNull("Classloader should be gced ", refa.get());
- assertNull("Classloader should be gced ", refb.get());
- }
-
- private static void forceOutOfMemoryError() throws Exception
- {
- ArrayList<String> list = new ArrayList<String>();
- try
- {
-
- long i = 0;
- while (true)
- {
-
list.add("BigBigBigBigBigBigBigBigBigBigBigBigBigBigBigBigBigBigBigBigBigBigBigBig"
+ (i++));
- }
- }
- catch (Throwable ignored)
- {
- }
- list.clear();
- list = null;
- System.gc();
- Thread.sleep(1000);
- }
-
- /**
- * Test replication with classloaders.
- *
- * @throws Exception
- */
- public void testCLLeakage() throws Exception
- {
- Person p = new Person();
- p.setName("Ben");
- Address add = new Address();
- add.setCity("Taipei");
-
- ClassLoader cla = getClassLoader();
- WeakReference<ClassLoader> refa = new WeakReference<ClassLoader>(cla);
- cache_.getCache().getRegion(new Fqn<String>("/aop"),
true).registerContextClassLoader(cla);
- ClassLoader clb = getClassLoader();
- cache1_.getCache().getRegion(new Fqn<String>("/aop"),
true).registerContextClassLoader(clb);
- WeakReference<ClassLoader> refb = new WeakReference<ClassLoader>(clb);
-
- cache_.attach("/aop", p);
-
- TestingUtil.sleepThread(100);
- try
- {
- Object ben = cache1_.find("/aop");
- assertEquals(p.toString(), ben.toString());
- ben = null;
- }
- catch (Exception ex)
- {
- fail("Test fails with exception " + ex);
- }
-
- cache_.detach("/aop");
- ClassLoader clc = getClassLoader();
- cache_.getCache().getRegion(new Fqn<String>("/aop"),
true).registerContextClassLoader(clc);
- cache1_.getCache().getRegion(new Fqn<String>("/aop"),
true).registerContextClassLoader(clc);
- cla = null;
- clb = null;
- forceOutOfMemoryError();
-
- assertNull("Classloader should be gced ", refa.get());
- assertNull("Classloader should be gced ", refb.get());
- }
-
- protected ClassLoader getClassLoader() throws Exception
- {
- String[] includesClasses = {"org.jboss.cache.aop.test.Person",
- "org.jboss.cache.aop.test.Address"};
- String[] excludesClasses = {};
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- return new SelectedClassnameClassLoader(includesClasses, excludesClasses, cl);
- }
-
-
-
-
-}
Copied: pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/memory/ReplicatedTest.java
(from rev 5129,
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/memory/ReplicatedTest.java)
===================================================================
--- pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/memory/ReplicatedTest.java
(rev 0)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/memory/ReplicatedTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -0,0 +1,186 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at
gnu.org.
+ */
+
+package org.jboss.cache.pojo.memory;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNull;
+import static org.testng.AssertJUnit.fail;
+
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.pojo.PojoCache;
+import org.jboss.cache.pojo.PojoCacheFactory;
+import org.jboss.cache.pojo.test.Address;
+import org.jboss.cache.pojo.test.Person;
+import org.jboss.cache.pojo.test.SerializedAddress;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * @author Ben Wang
+ */
+
+@Test(groups = {"functional"})
+public class ReplicatedTest
+{
+ Log log_ = LogFactory.getLog(ReplicatedTest.class);
+ PojoCache cache_;
+ PojoCache cache1_;
+
+
+ @BeforeMethod(alwaysRun = true)
+ protected void setUp() throws Exception
+ {
+ boolean toStart = false;
+ cache_ =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
+ cache_.start();
+ cache1_ =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
+ cache1_.start();
+ }
+
+ @AfterMethod(alwaysRun = true)
+ protected void tearDown() throws Exception
+ {
+ cache_.stop();
+ cache1_.stop();
+ }
+
+// public void testDummy() {}
+
+ /**
+ * Test replication with classloaders.
+ *
+ * @throws Exception
+ */
+ public void testCLLeakageBasic() throws Exception
+ {
+ SerializedAddress add = new SerializedAddress();
+ add.setCity("Taipei");
+
+ ClassLoader cla = getClassLoader();
+ WeakReference<ClassLoader> refa = new WeakReference<ClassLoader>(cla);
+ cache_.getCache().getRegion(new Fqn<String>("/aop"),
true).registerContextClassLoader(cla);
+ ClassLoader clb = getClassLoader();
+ WeakReference<ClassLoader> refb = new WeakReference<ClassLoader>(clb);
+ cache_.getCache().getRegion(new Fqn<String>("/aop"),
true).registerContextClassLoader(clb);
+
+ Fqn<String> fqn = new Fqn<String>("/aop");
+ cache_.getCache().put(new Fqn<String>("/aop"), "add",
add);
+
+ TestingUtil.sleepThread(100);
+ try
+ {
+ Object ben = cache1_.getCache().get(fqn, "add");
+ assertEquals(add.toString(), ben.toString());
+ ben = null;
+ }
+ catch (Exception ex)
+ {
+ fail("Test fails with exception " + ex);
+ }
+
+ cache_.getCache().remove(fqn, "add");
+
+ ClassLoader clc = getClassLoader();
+ cla = null;
+ clb = null;
+ cache_.getCache().getRegion(new Fqn<String>("/aop"),
true).registerContextClassLoader(clc);
+ cache1_.getCache().getRegion(new Fqn<String>("/aop"),
true).registerContextClassLoader(clc);
+ System.gc(); // force gc
+ Thread.sleep(1000);
+ assertNull("Classloader should be gced ", refa.get());
+ assertNull("Classloader should be gced ", refb.get());
+ }
+
+ private static void forceOutOfMemoryError() throws Exception
+ {
+ ArrayList<String> list = new ArrayList<String>();
+ try
+ {
+
+ long i = 0;
+ while (true)
+ {
+
list.add("BigBigBigBigBigBigBigBigBigBigBigBigBigBigBigBigBigBigBigBigBigBigBigBig"
+ (i++));
+ }
+ }
+ catch (Throwable ignored)
+ {
+ }
+ list.clear();
+ list = null;
+ System.gc();
+ Thread.sleep(1000);
+ }
+
+ /**
+ * Test replication with classloaders.
+ *
+ * @throws Exception
+ */
+ public void testCLLeakage() throws Exception
+ {
+ Person p = new Person();
+ p.setName("Ben");
+ Address add = new Address();
+ add.setCity("Taipei");
+
+ ClassLoader cla = getClassLoader();
+ WeakReference<ClassLoader> refa = new WeakReference<ClassLoader>(cla);
+ cache_.getCache().getRegion(new Fqn<String>("/aop"),
true).registerContextClassLoader(cla);
+ ClassLoader clb = getClassLoader();
+ cache1_.getCache().getRegion(new Fqn<String>("/aop"),
true).registerContextClassLoader(clb);
+ WeakReference<ClassLoader> refb = new WeakReference<ClassLoader>(clb);
+
+ cache_.attach("/aop", p);
+
+ TestingUtil.sleepThread(100);
+ try
+ {
+ Object ben = cache1_.find("/aop");
+ assertEquals(p.toString(), ben.toString());
+ ben = null;
+ }
+ catch (Exception ex)
+ {
+ fail("Test fails with exception " + ex);
+ }
+
+ cache_.detach("/aop");
+ ClassLoader clc = getClassLoader();
+ cache_.getCache().getRegion(new Fqn<String>("/aop"),
true).registerContextClassLoader(clc);
+ cache1_.getCache().getRegion(new Fqn<String>("/aop"),
true).registerContextClassLoader(clc);
+ cla = null;
+ clb = null;
+ forceOutOfMemoryError();
+
+ assertNull("Classloader should be gced ", refa.get());
+ assertNull("Classloader should be gced ", refb.get());
+ }
+
+ protected ClassLoader getClassLoader() throws Exception
+ {
+ String[] includesClasses = {"org.jboss.cache.aop.test.Person",
+ "org.jboss.cache.aop.test.Address"};
+ String[] excludesClasses = {};
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ return new SelectedClassnameClassLoader(includesClasses, excludesClasses, cl);
+ }
+
+
+
+
+}
Deleted:
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/optimistic/AbstractOptimisticTestCase.java
===================================================================
---
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/optimistic/AbstractOptimisticTestCase.java 2007-11-26
18:16:13 UTC (rev 4776)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/optimistic/AbstractOptimisticTestCase.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -1,378 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.jboss.cache.pojo.optimistic;
-
-import java.io.File;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Random;
-
-import javax.transaction.SystemException;
-import javax.transaction.TransactionManager;
-
-import org.jboss.cache.CacheSPI;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.factories.XmlConfigurationParser;
-import org.jboss.cache.interceptors.Interceptor;
-import org.jboss.cache.interceptors.InvocationContextInterceptor;
-import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
-import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
-import org.jboss.cache.interceptors.OptimisticReplicationInterceptor;
-import org.jboss.cache.interceptors.TxInterceptor;
-import org.jboss.cache.lock.IsolationLevel;
-import org.jboss.cache.marshall.MethodCall;
-import org.jboss.cache.marshall.MethodCallFactory;
-import org.jboss.cache.marshall.MethodDeclarations;
-import org.jboss.cache.misc.TestingUtil;
-import org.jboss.cache.optimistic.DefaultDataVersion;
-import org.jboss.cache.optimistic.TestListener;
-import org.jboss.cache.pojo.PojoCache;
-import org.jboss.cache.pojo.PojoCacheFactory;
-import org.jboss.cache.transaction.DummyTransactionManager;
-import org.jboss.cache.xml.XmlHelper;
-import org.testng.annotations.AfterMethod;
-import org.w3c.dom.Element;
-
-/**
- * Base test for optimistic locking. Copied from Cache counterpart.
- */
-public abstract class AbstractOptimisticTestCase
-{
- private int instanceNumber;
-
- // some test data shared among all the test cases
- protected Fqn<String> fqn = Fqn.fromString("/blah");
- protected String key = "myKey", value = "myValue";
-
- protected String getTempDir()
- {
- return getTempDir("tempdir");
- }
-
- private String getTempDir(String name)
- {
- String tempDir = System.getProperty("java.io.tmpdir", "/tmp");
- tempDir = tempDir + File.separator + name;
- System.out.println("tmpdir property: " +
System.getProperty("java.io.tmpdir"));
- System.out.println("Attempting to create dir [" + tempDir +
"]");
- File tempDirFile = new File(tempDir);
- if (!tempDirFile.exists())
- {
- tempDirFile.mkdirs();
- }
- return tempDir;
- }
-
- protected PojoCache createCacheUnstarted() throws Exception
- {
- return createCacheUnstarted(true);
- }
-
- protected PojoCache createCacheUnstarted(boolean optimistic) throws Exception
- {
- Configuration c = new Configuration();
- if (optimistic) c.setNodeLockingScheme("OPTIMISTIC");
-
-
c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
- c.setCacheMode("LOCAL");
- PojoCache cache = PojoCacheFactory.createCache(c, false);
- return cache;
- }
-
- protected PojoCache createCacheWithListener() throws Exception
- {
- return createCacheWithListener(new TestListener());
- }
-
- protected PojoCache createCacheWithListener(Object listener) throws Exception
- {
- PojoCache cache = createCacheUnstarted();
- cache.create();
- cache.start();
- cache.getCache().addCacheListener(listener);
- return cache;
- }
-
- /**
- * Returns a tree cache with passivation disabled in the loader.
- *
- * @return
- * @throws Exception
- */
- protected PojoCache createCacheWithLoader() throws Exception
- {
- return createCacheWithLoader(false);
- }
-
- protected CacheLoaderConfig getCacheLoaderConfig(boolean shared, String filename,
boolean passivation) throws Exception
- {
- String xml = " <config>\n" +
- " <passivation>" + passivation +
"</passivation>\n" +
- " <preload></preload>\n" +
- " <shared>" + shared +
"</shared>\n" +
- " <cacheloader>\n" +
- "
<class>org.jboss.cache.loader.FileCacheLoader</class>\n" +
- " <properties>\n" +
- " </properties>\n" +
- " <async>false</async>\n" +
- " <fetchPersistentState>" + (!shared) +
"</fetchPersistentState>\n" +
- "
<ignoreModifications>false</ignoreModifications>\n" +
- " </cacheloader>\n" +
- " </config>";
- Element element = XmlHelper.stringToElement(xml);
- return XmlConfigurationParser.parseCacheLoaderConfig(element);
- }
-
- protected PojoCache createCacheWithLoader(boolean passivationEnabled) throws
Exception
- {
- PojoCache cache = createCacheUnstarted();
- Configuration c = cache.getCache().getConfiguration();
- c.setCacheLoaderConfig(getCacheLoaderConfig(true, getTempDir(),
passivationEnabled));
- cache.create();
- cache.start();
- return cache;
- }
-
- protected PojoCache createCache() throws Exception
- {
- PojoCache cache = createCacheUnstarted();
- cache.create();
- cache.start();
- return cache;
- }
-
- protected void destroyCache(PojoCache c)
- {
- c.stop();
- c.destroy();
- }
-
-
- protected PojoCache createPessimisticCache() throws Exception
- {
- Configuration c = new Configuration();
- c.setClusterName("name");
- c.setStateRetrievalTimeout(5000);
- c.setClusterConfig(getDefaultProperties());
- c.setCacheMode(Configuration.CacheMode.REPL_SYNC);
- c.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
-
c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
-
- PojoCache cache = PojoCacheFactory.createCache(c, false);
- cache.create();
- cache.start();
-
-
- return cache;
- }
-
- protected PojoCache createPessimisticCacheLocal() throws Exception
- {
- Configuration c = new Configuration();
-
- c.setClusterName("name");
- c.setStateRetrievalTimeout(5000);
- c.setClusterConfig(getDefaultProperties());
-
- c.setCacheMode(Configuration.CacheMode.LOCAL);
- c.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
-
c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
- PojoCache cache = PojoCacheFactory.createCache(c, false);
- cache.create();
- cache.start();
-
- return cache;
- }
-
- protected String getDefaultProperties()
- {
- return "UDP(mcast_addr=228.1.2.3;mcast_port=48866;ip_ttl=32;" +
-
"mcast_send_buf_size=150000;mcast_recv_buf_size=80000;loopback=true;ip_mcast=true;bind_addr=127.0.0.1):"
+
- "PING(timeout=1000;num_initial_members=2):" +
- "MERGE2(min_interval=5000;max_interval=10000):" +
- "FD_SOCK:" +
- "VERIFY_SUSPECT(timeout=1500):" +
-
"pbcast.NAKACK(gc_lag=50;max_xmit_size=8192;retransmit_timeout=600,1200,2400,4800):"
+
- "UNICAST(timeout=600,1200,2400,4800):" +
- "pbcast.STABLE(desired_avg_gossip=20000):" +
- "FRAG(frag_size=8192;down_thread=false;up_thread=false):" +
- "pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;" +
- "shun=false;print_local_addr=true):" +
- "pbcast.STATE_TRANSFER";
- }
-
- protected PojoCache createReplicatedCache(Configuration.CacheMode mode) throws
Exception
- {
- return createReplicatedCache("test", mode);
- }
-
- protected PojoCache createReplicatedCache(String name, Configuration.CacheMode mode)
throws Exception
- {
- Configuration c = new Configuration();
-
- c.setClusterName(name);
- c.setStateRetrievalTimeout(5000);
- c.setClusterConfig(getDefaultProperties());
- c.setCacheMode(mode);
- if (mode == Configuration.CacheMode.REPL_SYNC)
- {
- // make sure commits and rollbacks are sync as well
- c.setSyncCommitPhase(true);
- c.setSyncRollbackPhase(true);
- }
- c.setNodeLockingScheme("OPTIMISTIC");
-
c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
- PojoCache cache = PojoCacheFactory.createCache(c, false);
- cache.create();
- cache.start();
-
- return cache;
- }
-
- protected PojoCache createReplicatedCacheWithLoader(boolean shared,
Configuration.CacheMode cacheMode) throws Exception
- {
- return createReplicatedCacheWithLoader("temp-loader", shared,
cacheMode);
- }
-
- protected PojoCache createReplicatedCacheWithLoader(boolean shared) throws Exception
- {
- return createReplicatedCacheWithLoader("temp-loader", shared,
Configuration.CacheMode.REPL_SYNC);
- }
-
- protected PojoCache createReplicatedCacheWithLoader(String name, boolean shared)
throws Exception
- {
- return createReplicatedCacheWithLoader(name, shared,
Configuration.CacheMode.REPL_SYNC);
- }
-
- protected PojoCache createReplicatedCacheWithLoader(String name, boolean shared,
Configuration.CacheMode cacheMode) throws Exception
- {
- Configuration c = new Configuration();
- c.setClusterName(name);
- c.setStateRetrievalTimeout(5000);
- c.setClusterConfig(getDefaultProperties());
- c.setCacheMode(cacheMode);
- c.setSyncCommitPhase(true);
- c.setSyncRollbackPhase(true);
- c.setNodeLockingScheme("OPTIMISTIC");
-
c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
- c.setCacheLoaderConfig(getCacheLoaderConfig(shared, shared ? getTempDir(name +
"-shared") : getTempDir(name + instanceNumber++), false));
-
- PojoCache cache = PojoCacheFactory.createCache(c, false);
- cache.create();
- cache.start();
- return cache;
- }
-
- protected Random random;
-
- protected void randomSleep(int min, int max)
- {
- if (random == null) random = new Random();
- long l = -1;
- while (l < min) l = random.nextInt(max);
- TestingUtil.sleepThread(l);
- }
-
- @AfterMethod(alwaysRun = true)
- protected void tearDown()
- {
- TransactionManager mgr = DummyTransactionManager.getInstance();
- try
- {
- if (mgr.getTransaction() != null)
- {
- mgr.rollback();
- }
- }
- catch (SystemException e)
- {
- // do nothing
- }
- }
-
- protected Interceptor getAlteredInterceptorChain(Interceptor newLast,
CacheSPI<Object, Object> spi, boolean replicated)
- {
- Interceptor ici = new InvocationContextInterceptor();
- ici.setCache(spi);
-
- Interceptor txInterceptor = new TxInterceptor();
- txInterceptor.setCache(spi);
-
- Interceptor replicationInterceptor = new OptimisticReplicationInterceptor();
- replicationInterceptor.setCache(spi);
-
- Interceptor createInterceptor = new OptimisticCreateIfNotExistsInterceptor();
- createInterceptor.setCache(spi);
-
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(spi);
-
- ici.setNext(txInterceptor);
- if (replicated)
- {
- txInterceptor.setNext(replicationInterceptor);
- replicationInterceptor.setNext(createInterceptor);
- }
- else
- {
- txInterceptor.setNext(createInterceptor);
- }
- createInterceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(newLast);
-
- return ici;
- }
-
- public abstract class ExceptionThread extends Thread
- {
- protected Exception exception;
-
- public void setException(Exception e)
- {
- exception = e;
- }
-
- public Exception getException()
- {
- return exception;
- }
- }
-
- protected List<MethodCall> injectDataVersion(List<MethodCall>
modifications)
- {
- List<MethodCall> newList = new LinkedList<MethodCall>();
- for (MethodCall c : modifications)
- {
- Object[] oa = c.getArgs();
- Object[] na = new Object[oa.length + 1];
- System.out.println("*** " + oa.length);
- System.arraycopy(oa, 0, na, 0, oa.length);
- na[oa.length] = new DefaultDataVersion();
-
newList.add(MethodCallFactory.create(MethodDeclarations.getVersionedMethod(c.getMethodId()),
na));
- }
- return newList;
- }
-
-}
Copied:
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/optimistic/AbstractOptimisticTestCase.java
(from rev 5129,
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/optimistic/AbstractOptimisticTestCase.java)
===================================================================
---
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/optimistic/AbstractOptimisticTestCase.java
(rev 0)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/optimistic/AbstractOptimisticTestCase.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -0,0 +1,378 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.jboss.cache.pojo.optimistic;
+
+import java.io.File;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Random;
+
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.config.CacheLoaderConfig;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.XmlConfigurationParser;
+import org.jboss.cache.interceptors.Interceptor;
+import org.jboss.cache.interceptors.InvocationContextInterceptor;
+import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
+import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
+import org.jboss.cache.interceptors.OptimisticReplicationInterceptor;
+import org.jboss.cache.interceptors.TxInterceptor;
+import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.cache.marshall.MethodCall;
+import org.jboss.cache.marshall.MethodCallFactory;
+import org.jboss.cache.marshall.MethodDeclarations;
+import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.optimistic.DefaultDataVersion;
+import org.jboss.cache.optimistic.TestListener;
+import org.jboss.cache.pojo.PojoCache;
+import org.jboss.cache.pojo.PojoCacheFactory;
+import org.jboss.cache.transaction.DummyTransactionManager;
+import org.jboss.cache.xml.XmlHelper;
+import org.testng.annotations.AfterMethod;
+import org.w3c.dom.Element;
+
+/**
+ * Base test for optimistic locking. Copied from Cache counterpart.
+ */
+public abstract class AbstractOptimisticTestCase
+{
+ private int instanceNumber;
+
+ // some test data shared among all the test cases
+ protected Fqn<String> fqn = Fqn.fromString("/blah");
+ protected String key = "myKey", value = "myValue";
+
+ protected String getTempDir()
+ {
+ return getTempDir("tempdir");
+ }
+
+ private String getTempDir(String name)
+ {
+ String tempDir = System.getProperty("java.io.tmpdir", "/tmp");
+ tempDir = tempDir + File.separator + name;
+ System.out.println("tmpdir property: " +
System.getProperty("java.io.tmpdir"));
+ System.out.println("Attempting to create dir [" + tempDir +
"]");
+ File tempDirFile = new File(tempDir);
+ if (!tempDirFile.exists())
+ {
+ tempDirFile.mkdirs();
+ }
+ return tempDir;
+ }
+
+ protected PojoCache createCacheUnstarted() throws Exception
+ {
+ return createCacheUnstarted(true);
+ }
+
+ protected PojoCache createCacheUnstarted(boolean optimistic) throws Exception
+ {
+ Configuration c = new Configuration();
+ if (optimistic) c.setNodeLockingScheme("OPTIMISTIC");
+
+
c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
+ c.setCacheMode("LOCAL");
+ PojoCache cache = PojoCacheFactory.createCache(c, false);
+ return cache;
+ }
+
+ protected PojoCache createCacheWithListener() throws Exception
+ {
+ return createCacheWithListener(new TestListener());
+ }
+
+ protected PojoCache createCacheWithListener(Object listener) throws Exception
+ {
+ PojoCache cache = createCacheUnstarted();
+ cache.create();
+ cache.start();
+ cache.getCache().addCacheListener(listener);
+ return cache;
+ }
+
+ /**
+ * Returns a tree cache with passivation disabled in the loader.
+ *
+ * @return
+ * @throws Exception
+ */
+ protected PojoCache createCacheWithLoader() throws Exception
+ {
+ return createCacheWithLoader(false);
+ }
+
+ protected CacheLoaderConfig getCacheLoaderConfig(boolean shared, String filename,
boolean passivation) throws Exception
+ {
+ String xml = " <config>\n" +
+ " <passivation>" + passivation +
"</passivation>\n" +
+ " <preload></preload>\n" +
+ " <shared>" + shared +
"</shared>\n" +
+ " <cacheloader>\n" +
+ "
<class>org.jboss.cache.loader.FileCacheLoader</class>\n" +
+ " <properties>\n" +
+ " </properties>\n" +
+ " <async>false</async>\n" +
+ " <fetchPersistentState>" + (!shared) +
"</fetchPersistentState>\n" +
+ "
<ignoreModifications>false</ignoreModifications>\n" +
+ " </cacheloader>\n" +
+ " </config>";
+ Element element = XmlHelper.stringToElement(xml);
+ return XmlConfigurationParser.parseCacheLoaderConfig(element);
+ }
+
+ protected PojoCache createCacheWithLoader(boolean passivationEnabled) throws
Exception
+ {
+ PojoCache cache = createCacheUnstarted();
+ Configuration c = cache.getCache().getConfiguration();
+ c.setCacheLoaderConfig(getCacheLoaderConfig(true, getTempDir(),
passivationEnabled));
+ cache.create();
+ cache.start();
+ return cache;
+ }
+
+ protected PojoCache createCache() throws Exception
+ {
+ PojoCache cache = createCacheUnstarted();
+ cache.create();
+ cache.start();
+ return cache;
+ }
+
+ protected void destroyCache(PojoCache c)
+ {
+ c.stop();
+ c.destroy();
+ }
+
+
+ protected PojoCache createPessimisticCache() throws Exception
+ {
+ Configuration c = new Configuration();
+ c.setClusterName("name");
+ c.setStateRetrievalTimeout(5000);
+ c.setClusterConfig(getDefaultProperties());
+ c.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ c.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
+
c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
+
+ PojoCache cache = PojoCacheFactory.createCache(c, false);
+ cache.create();
+ cache.start();
+
+
+ return cache;
+ }
+
+ protected PojoCache createPessimisticCacheLocal() throws Exception
+ {
+ Configuration c = new Configuration();
+
+ c.setClusterName("name");
+ c.setStateRetrievalTimeout(5000);
+ c.setClusterConfig(getDefaultProperties());
+
+ c.setCacheMode(Configuration.CacheMode.LOCAL);
+ c.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
+
c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
+ PojoCache cache = PojoCacheFactory.createCache(c, false);
+ cache.create();
+ cache.start();
+
+ return cache;
+ }
+
+ protected String getDefaultProperties()
+ {
+ return "UDP(mcast_addr=228.1.2.3;mcast_port=48866;ip_ttl=32;" +
+
"mcast_send_buf_size=150000;mcast_recv_buf_size=80000;loopback=true;ip_mcast=true;bind_addr=127.0.0.1):"
+
+ "PING(timeout=1000;num_initial_members=2):" +
+ "MERGE2(min_interval=5000;max_interval=10000):" +
+ "FD_SOCK:" +
+ "VERIFY_SUSPECT(timeout=1500):" +
+
"pbcast.NAKACK(gc_lag=50;max_xmit_size=8192;retransmit_timeout=600,1200,2400,4800):"
+
+ "UNICAST(timeout=600,1200,2400,4800):" +
+ "pbcast.STABLE(desired_avg_gossip=20000):" +
+ "FRAG(frag_size=8192;down_thread=false;up_thread=false):" +
+ "pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;" +
+ "shun=false;print_local_addr=true):" +
+ "pbcast.STATE_TRANSFER";
+ }
+
+ protected PojoCache createReplicatedCache(Configuration.CacheMode mode) throws
Exception
+ {
+ return createReplicatedCache("test", mode);
+ }
+
+ protected PojoCache createReplicatedCache(String name, Configuration.CacheMode mode)
throws Exception
+ {
+ Configuration c = new Configuration();
+
+ c.setClusterName(name);
+ c.setStateRetrievalTimeout(5000);
+ c.setClusterConfig(getDefaultProperties());
+ c.setCacheMode(mode);
+ if (mode == Configuration.CacheMode.REPL_SYNC)
+ {
+ // make sure commits and rollbacks are sync as well
+ c.setSyncCommitPhase(true);
+ c.setSyncRollbackPhase(true);
+ }
+ c.setNodeLockingScheme("OPTIMISTIC");
+
c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
+ PojoCache cache = PojoCacheFactory.createCache(c, false);
+ cache.create();
+ cache.start();
+
+ return cache;
+ }
+
+ protected PojoCache createReplicatedCacheWithLoader(boolean shared,
Configuration.CacheMode cacheMode) throws Exception
+ {
+ return createReplicatedCacheWithLoader("temp-loader", shared,
cacheMode);
+ }
+
+ protected PojoCache createReplicatedCacheWithLoader(boolean shared) throws Exception
+ {
+ return createReplicatedCacheWithLoader("temp-loader", shared,
Configuration.CacheMode.REPL_SYNC);
+ }
+
+ protected PojoCache createReplicatedCacheWithLoader(String name, boolean shared)
throws Exception
+ {
+ return createReplicatedCacheWithLoader(name, shared,
Configuration.CacheMode.REPL_SYNC);
+ }
+
+ protected PojoCache createReplicatedCacheWithLoader(String name, boolean shared,
Configuration.CacheMode cacheMode) throws Exception
+ {
+ Configuration c = new Configuration();
+ c.setClusterName(name);
+ c.setStateRetrievalTimeout(5000);
+ c.setClusterConfig(getDefaultProperties());
+ c.setCacheMode(cacheMode);
+ c.setSyncCommitPhase(true);
+ c.setSyncRollbackPhase(true);
+ c.setNodeLockingScheme("OPTIMISTIC");
+
c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
+ c.setCacheLoaderConfig(getCacheLoaderConfig(shared, shared ? getTempDir(name +
"-shared") : getTempDir(name + instanceNumber++), false));
+
+ PojoCache cache = PojoCacheFactory.createCache(c, false);
+ cache.create();
+ cache.start();
+ return cache;
+ }
+
+ protected Random random;
+
+ protected void randomSleep(int min, int max)
+ {
+ if (random == null) random = new Random();
+ long l = -1;
+ while (l < min) l = random.nextInt(max);
+ TestingUtil.sleepThread(l);
+ }
+
+ @AfterMethod(alwaysRun = true)
+ protected void tearDown()
+ {
+ TransactionManager mgr = DummyTransactionManager.getInstance();
+ try
+ {
+ if (mgr.getTransaction() != null)
+ {
+ mgr.rollback();
+ }
+ }
+ catch (SystemException e)
+ {
+ // do nothing
+ }
+ }
+
+ protected Interceptor getAlteredInterceptorChain(Interceptor newLast,
CacheSPI<Object, Object> spi, boolean replicated)
+ {
+ Interceptor ici = new InvocationContextInterceptor();
+ ici.setCache(spi);
+
+ Interceptor txInterceptor = new TxInterceptor();
+ txInterceptor.setCache(spi);
+
+ Interceptor replicationInterceptor = new OptimisticReplicationInterceptor();
+ replicationInterceptor.setCache(spi);
+
+ Interceptor createInterceptor = new OptimisticCreateIfNotExistsInterceptor();
+ createInterceptor.setCache(spi);
+
+ Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
+ nodeInterceptor.setCache(spi);
+
+ ici.setNext(txInterceptor);
+ if (replicated)
+ {
+ txInterceptor.setNext(replicationInterceptor);
+ replicationInterceptor.setNext(createInterceptor);
+ }
+ else
+ {
+ txInterceptor.setNext(createInterceptor);
+ }
+ createInterceptor.setNext(nodeInterceptor);
+ nodeInterceptor.setNext(newLast);
+
+ return ici;
+ }
+
+ public abstract class ExceptionThread extends Thread
+ {
+ protected Exception exception;
+
+ public void setException(Exception e)
+ {
+ exception = e;
+ }
+
+ public Exception getException()
+ {
+ return exception;
+ }
+ }
+
+ protected List<MethodCall> injectDataVersion(List<MethodCall>
modifications)
+ {
+ List<MethodCall> newList = new LinkedList<MethodCall>();
+ for (MethodCall c : modifications)
+ {
+ Object[] oa = c.getArgs();
+ Object[] na = new Object[oa.length + 1];
+ System.out.println("*** " + oa.length);
+ System.arraycopy(oa, 0, na, 0, oa.length);
+ na[oa.length] = new DefaultDataVersion();
+ newList.add(MethodCallFactory.create(c.getMethodId(), na));
+ }
+ return newList;
+ }
+
+}
Deleted:
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/region/LocalConcurrentTest.java
===================================================================
---
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/region/LocalConcurrentTest.java 2007-11-26
18:16:13 UTC (rev 4776)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/region/LocalConcurrentTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -1,268 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at
gnu.org.
- */
-
-package org.jboss.cache.pojo.region;
-
-import java.util.ArrayList;
-import java.util.Properties;
-import java.util.Random;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.transaction.UserTransaction;
-
-import org.jboss.cache.Fqn;
-import org.jboss.cache.lock.UpgradeException;
-import org.jboss.cache.pojo.PojoCache;
-import org.jboss.cache.pojo.PojoCacheFactory;
-import org.jboss.cache.pojo.TestingUtil;
-import org.jboss.cache.pojo.test.Address;
-import org.jboss.cache.pojo.test.Person;
-import org.jboss.cache.transaction.DummyTransactionManager;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-/**
- * Local concurrent test for PojoCache. Test attach and detach under load
- * and concurrency.
- *
- * @version $Revision$
- * @author<a href="mailto:bwang@jboss.org">Ben Wang</a> December
2004
- */
-@Test(groups = {"functional"}, enabled = false)
-public class LocalConcurrentTest
-{
- static PojoCache cache_;
- Properties p_;
- String oldFactory_ = null;
- final String FACTORY = "org.jboss.cache.transaction.DummyContextFactory";
- static ArrayList<String> nodeList_;
- static final int depth_ = 2;
- static final int children_ = 2;
- static final int MAX_LOOP = 100;
- static final int SLEEP_TIME = 50;
- static Exception thread_ex = null;
- UserTransaction tx_ = null;
-
- @BeforeMethod(alwaysRun = true)
- public void setUp() throws Exception
- {
- oldFactory_ = System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
- System.setProperty(Context.INITIAL_CONTEXT_FACTORY, FACTORY);
- DummyTransactionManager.getInstance();
- if (p_ == null)
- {
- p_ = new Properties();
- p_.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.cache.transaction.DummyContextFactory");
- }
-
- tx_ = (UserTransaction) new
InitialContext(p_).lookup("UserTransaction");
-
- initCaches();
- nodeList_ = nodeGen(depth_, children_);
-
- log("LocalConcurrentTestCase: cacheMode=TRANSIENT, one cache");
- }
-
- @AfterMethod(alwaysRun = true)
- public void tearDown() throws Exception
- {
- thread_ex = null;
- DummyTransactionManager.destroy();
- destroyCaches();
-
- if (oldFactory_ != null)
- {
- System.setProperty(Context.INITIAL_CONTEXT_FACTORY, oldFactory_);
- oldFactory_ = null;
- }
-
- }
-
- void initCaches() throws Exception
- {
- boolean toStart = false;
- cache_ = PojoCacheFactory.createCache("META-INF/local-service.xml",
toStart);
- cache_.start();
- }
-
- void destroyCaches() throws Exception
- {
- cache_.stop();
- cache_ = null;
- }
-
- public void testAll_RWLock() throws Exception
- {
- try
- {
- all();
- }
- catch (UpgradeException ue)
- {
- log("Upgrade exception. Can ingore for repeatable read. " + ue);
- }
- catch (Exception ex)
- {
- log("Exception: " + ex);
- throw ex;
- }
- }
-
- private void all() throws Exception
- {
- RunThread t1 = new RunThread(1, "t1");
- RunThread t2 = new RunThread(2, "t2");
- RunThread t3 = new RunThread(3, "t3");
- RunThread t4 = new RunThread(4, "t4");
-
- t1.start();
- TestingUtil.sleepThread(100);
- t2.start();
- TestingUtil.sleepThread(100);
- t3.start();
- TestingUtil.sleepThread(100);
- t4.start();
-
- t1.join(60000); // wait for 20 secs
- t2.join(60000); // wait for 20 secs
- t3.join(60000); // wait for 20 secs
- t4.join(60000); // wait for 20 secs
-
- if (thread_ex != null)
- throw thread_ex;
- }
-
- class RunThread extends Thread
- {
- final int seed_;
- Random random_;
- Person person_;
-
- public RunThread(int seed, String threadName)
- {
- super(threadName);
- seed_ = seed;
- random_ = new Random(seed);
- }
-
- private void createPerson()
- {
- person_ = new Person();
- person_.setName("Ben");
- person_.setAge(18);
- ArrayList<String> lang = new ArrayList<String>();
- lang.add("English");
- lang.add("French");
- lang.add("Mandarin");
- person_.setLanguages(lang);
- Address addr = new Address();
- addr.setZip(95123);
- addr.setStreet("Almeria");
- addr.setCity("San Jose");
- person_.setAddress(addr);
- }
-
- public void run()
- {
- try
- {
- cache_.getCache().getRegion(Fqn.fromString(Thread.currentThread().getName()),
true);
- _run();
- }
- catch (Exception e)
- {
- thread_ex = e;
- }
- }
-
- /**
- */
- public void _run() throws Exception
- {
- for (int loop = 0; loop < MAX_LOOP; loop++)
- {
- createPerson(); // create a new person instance every loop.
- op1();
- }
- }
-
- // Operation 1
- private void op1()
- {
- int i = random_.nextInt(nodeList_.size() - 1);
- if (i == 0) return; // it is meaningless to test root
- String node = nodeList_.get(i) + "/aop";
- cache_.attach(node, person_);
- TestingUtil.sleepThread(random_.nextInt(SLEEP_TIME)); // sleep for max 200
millis
- TestingUtil.sleepThread(random_.nextInt(SLEEP_TIME)); // sleep for max 200
millis
- cache_.detach(node);
- }
- }
-
- /**
- * Generate the tree nodes quasi-exponentially. I.e., depth is the level
- * of the hierarchy and children is the number of children under each node.
- * This strucutre is used to add, get, and remove for each node.
- */
- private ArrayList<String> nodeGen(int depth, int children)
- {
- ArrayList<String> strList = new ArrayList<String>();
- ArrayList<String> oldList = new ArrayList<String>();
- ArrayList<String> newList = new ArrayList<String>();
-
- // Skip root node
- String str = Thread.currentThread().getName();
- oldList.add(str);
- newList.add(str);
- strList.add(str);
-
- while (depth > 0)
- {
- // Trying to produce node name at this depth.
- newList = new ArrayList<String>();
- for (int i = 0; i < oldList.size(); i++)
- {
- for (int j = 0; j < children; j++)
- {
- String tmp = oldList.get(i);
- tmp += Integer.toString(j);
- if (depth != 1)
- {
- tmp += "/";
- }
-
- newList.add(tmp);
- }
- }
- strList.addAll(newList);
- oldList = newList;
- depth--;
- }
-
- // let's prune out root node
- for (int i = 0; i < strList.size(); i++)
- {
- if (strList.get(i).equals("/"))
- {
- strList.remove(i);
- break;
- }
- }
- log("Nodes generated: " + strList.size());
- return strList;
- }
-
-
- private static void log(String str)
- {
- System.out.println("Thread: " + Thread.currentThread() + ": " +
str);
-// System.out.println(str);
- }
-
-}
Copied:
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/region/LocalConcurrentTest.java
(from rev 5129,
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/region/LocalConcurrentTest.java)
===================================================================
---
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/region/LocalConcurrentTest.java
(rev 0)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/region/LocalConcurrentTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -0,0 +1,268 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at
gnu.org.
+ */
+
+package org.jboss.cache.pojo.region;
+
+import java.util.ArrayList;
+import java.util.Properties;
+import java.util.Random;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.transaction.UserTransaction;
+
+import org.jboss.cache.Fqn;
+import org.jboss.cache.lock.UpgradeException;
+import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.pojo.PojoCache;
+import org.jboss.cache.pojo.PojoCacheFactory;
+import org.jboss.cache.pojo.test.Address;
+import org.jboss.cache.pojo.test.Person;
+import org.jboss.cache.transaction.DummyTransactionManager;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Local concurrent test for PojoCache. Test attach and detach under load
+ * and concurrency.
+ *
+ * @version $Revision$
+ * @author<a href="mailto:bwang@jboss.org">Ben Wang</a> December
2004
+ */
+@Test(groups = {"functional"}, enabled = false)
+public class LocalConcurrentTest
+{
+ static PojoCache cache_;
+ Properties p_;
+ String oldFactory_ = null;
+ final String FACTORY = "org.jboss.cache.transaction.DummyContextFactory";
+ static ArrayList<String> nodeList_;
+ static final int depth_ = 2;
+ static final int children_ = 2;
+ static final int MAX_LOOP = 100;
+ static final int SLEEP_TIME = 50;
+ static Exception thread_ex = null;
+ UserTransaction tx_ = null;
+
+ @BeforeMethod(alwaysRun = true)
+ public void setUp() throws Exception
+ {
+ oldFactory_ = System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
+ System.setProperty(Context.INITIAL_CONTEXT_FACTORY, FACTORY);
+ DummyTransactionManager.getInstance();
+ if (p_ == null)
+ {
+ p_ = new Properties();
+ p_.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.cache.transaction.DummyContextFactory");
+ }
+
+ tx_ = (UserTransaction) new
InitialContext(p_).lookup("UserTransaction");
+
+ initCaches();
+ nodeList_ = nodeGen(depth_, children_);
+
+ log("LocalConcurrentTestCase: cacheMode=TRANSIENT, one cache");
+ }
+
+ @AfterMethod(alwaysRun = true)
+ public void tearDown() throws Exception
+ {
+ thread_ex = null;
+ DummyTransactionManager.destroy();
+ destroyCaches();
+
+ if (oldFactory_ != null)
+ {
+ System.setProperty(Context.INITIAL_CONTEXT_FACTORY, oldFactory_);
+ oldFactory_ = null;
+ }
+
+ }
+
+ void initCaches() throws Exception
+ {
+ boolean toStart = false;
+ cache_ = PojoCacheFactory.createCache("META-INF/local-service.xml",
toStart);
+ cache_.start();
+ }
+
+ void destroyCaches() throws Exception
+ {
+ cache_.stop();
+ cache_ = null;
+ }
+
+ public void testAll_RWLock() throws Exception
+ {
+ try
+ {
+ all();
+ }
+ catch (UpgradeException ue)
+ {
+ log("Upgrade exception. Can ingore for repeatable read. " + ue);
+ }
+ catch (Exception ex)
+ {
+ log("Exception: " + ex);
+ throw ex;
+ }
+ }
+
+ private void all() throws Exception
+ {
+ RunThread t1 = new RunThread(1, "t1");
+ RunThread t2 = new RunThread(2, "t2");
+ RunThread t3 = new RunThread(3, "t3");
+ RunThread t4 = new RunThread(4, "t4");
+
+ t1.start();
+ TestingUtil.sleepThread(100);
+ t2.start();
+ TestingUtil.sleepThread(100);
+ t3.start();
+ TestingUtil.sleepThread(100);
+ t4.start();
+
+ t1.join(60000); // wait for 20 secs
+ t2.join(60000); // wait for 20 secs
+ t3.join(60000); // wait for 20 secs
+ t4.join(60000); // wait for 20 secs
+
+ if (thread_ex != null)
+ throw thread_ex;
+ }
+
+ class RunThread extends Thread
+ {
+ final int seed_;
+ Random random_;
+ Person person_;
+
+ public RunThread(int seed, String threadName)
+ {
+ super(threadName);
+ seed_ = seed;
+ random_ = new Random(seed);
+ }
+
+ private void createPerson()
+ {
+ person_ = new Person();
+ person_.setName("Ben");
+ person_.setAge(18);
+ ArrayList<String> lang = new ArrayList<String>();
+ lang.add("English");
+ lang.add("French");
+ lang.add("Mandarin");
+ person_.setLanguages(lang);
+ Address addr = new Address();
+ addr.setZip(95123);
+ addr.setStreet("Almeria");
+ addr.setCity("San Jose");
+ person_.setAddress(addr);
+ }
+
+ public void run()
+ {
+ try
+ {
+ cache_.getCache().getRegion(Fqn.fromString(Thread.currentThread().getName()),
true);
+ _run();
+ }
+ catch (Exception e)
+ {
+ thread_ex = e;
+ }
+ }
+
+ /**
+ */
+ public void _run() throws Exception
+ {
+ for (int loop = 0; loop < MAX_LOOP; loop++)
+ {
+ createPerson(); // create a new person instance every loop.
+ op1();
+ }
+ }
+
+ // Operation 1
+ private void op1()
+ {
+ int i = random_.nextInt(nodeList_.size() - 1);
+ if (i == 0) return; // it is meaningless to test root
+ String node = nodeList_.get(i) + "/aop";
+ cache_.attach(node, person_);
+ TestingUtil.sleepThread(random_.nextInt(SLEEP_TIME)); // sleep for max 200
millis
+ TestingUtil.sleepThread(random_.nextInt(SLEEP_TIME)); // sleep for max 200
millis
+ cache_.detach(node);
+ }
+ }
+
+ /**
+ * Generate the tree nodes quasi-exponentially. I.e., depth is the level
+ * of the hierarchy and children is the number of children under each node.
+ * This strucutre is used to add, get, and remove for each node.
+ */
+ private ArrayList<String> nodeGen(int depth, int children)
+ {
+ ArrayList<String> strList = new ArrayList<String>();
+ ArrayList<String> oldList = new ArrayList<String>();
+ ArrayList<String> newList = new ArrayList<String>();
+
+ // Skip root node
+ String str = Thread.currentThread().getName();
+ oldList.add(str);
+ newList.add(str);
+ strList.add(str);
+
+ while (depth > 0)
+ {
+ // Trying to produce node name at this depth.
+ newList = new ArrayList<String>();
+ for (int i = 0; i < oldList.size(); i++)
+ {
+ for (int j = 0; j < children; j++)
+ {
+ String tmp = oldList.get(i);
+ tmp += Integer.toString(j);
+ if (depth != 1)
+ {
+ tmp += "/";
+ }
+
+ newList.add(tmp);
+ }
+ }
+ strList.addAll(newList);
+ oldList = newList;
+ depth--;
+ }
+
+ // let's prune out root node
+ for (int i = 0; i < strList.size(); i++)
+ {
+ if (strList.get(i).equals("/"))
+ {
+ strList.remove(i);
+ break;
+ }
+ }
+ log("Nodes generated: " + strList.size());
+ return strList;
+ }
+
+
+ private static void log(String str)
+ {
+ System.out.println("Thread: " + Thread.currentThread() + ": " +
str);
+// System.out.println(str);
+ }
+
+}
Deleted: pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/region/LocalTest.java
===================================================================
--- pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/region/LocalTest.java 2007-11-26
18:16:13 UTC (rev 4776)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/region/LocalTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -1,374 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at
gnu.org.
- */
-
-package org.jboss.cache.pojo.region;
-
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.aop.proxy.ClassProxy;
-import org.jboss.cache.CacheImpl;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.Node;
-import org.jboss.cache.pojo.PojoCache;
-import org.jboss.cache.pojo.PojoCacheFactory;
-import org.jboss.cache.pojo.impl.InternalConstant;
-import org.jboss.cache.pojo.test.Address;
-import org.jboss.cache.pojo.test.Person;
-import org.jboss.cache.pojo.test.Student;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-/**
- * Basic PojoCache test case.
- *
- * @author Ben Wang
- */
-
-@Test(groups = {"functional"})
-public class LocalTest
-{
- Log log = LogFactory.getLog(org.jboss.cache.pojo.region.LocalTest.class);
- PojoCache cache_;
- static final String REGION = "person";
-
-
- @BeforeMethod(alwaysRun = true)
- protected void setUp() throws Exception
- {
- log.info("setUp() ....");
- String configFile = "META-INF/local-service.xml";
- boolean toStart = false;
- cache_ = PojoCacheFactory.createCache(configFile, toStart);
- cache_.start();
- cache_.getCache().getRegion(Fqn.fromString(REGION), true);
- cache_.getCache().getRegion(Fqn.fromString("RANDOM"), true);
- }
-
- @AfterMethod(alwaysRun = true)
- protected void tearDown() throws Exception
- {
- cache_.stop();
- }
-
-// public void testDummy() {}
-
- private Person createPerson(String id, String name, int age)
- {
- Person p = new Person();
- p.setName(name);
- p.setAge(age);
- Address add = new Address();
- add.setZip(95123);
- add.setCity("San Jose");
- p.setAddress(add);
- cache_.attach(id, p);
- return p;
- }
-
- private Student createStudent(String id, String name, int age, String grade)
- {
- Student p = new Student();
- p.setName(name);
- p.setAge(age);
- p.setYear(grade);
- Address add = new Address();
- add.setZip(95123);
- add.setCity("San Jose");
- p.setAddress(add);
- cache_.attach(id, p);
- return p;
- }
-
- public void testSimple() throws Exception
- {
- log.info("testSimple() ....");
- Person p = createPerson("person/test1", "Joe Black", 32);
- assertEquals((Object) "Joe Black", p.getName());
-
- assertTrue("Region node should exist ",
- cache_.getCache().getRoot().hasChild(new Fqn<String>(REGION)));
- Fqn<String> fqn = new Fqn<String>(Fqn.fromString(REGION),
InternalConstant.JBOSS_INTERNAL);
- assertTrue("Internal region node should exist ",
- cache_.getCache().getRoot().hasChild(fqn));
- System.out.println("Cache content: "
+((org.jboss.cache.CacheImpl<Object, Object>)cache_.getCache()).printDetails());
- }
-
- public void testModification() throws Exception
- {
- Person joe = createPerson("person/test2", "Joe", 32);
- joe.setName("Joe Black");
- assertEquals(joe.getName(), "Joe Black");
- cache_.detach("person/test2");
- }
-
- public void testRemove() throws Exception
- {
- createPerson("person/test3", "Joe", 32);
- cache_.detach("person/test3");
-
- String str = ((CacheImpl<Object, Object>) cache_.getCache()).printDetails();
- System.out.println("**** Details ***/n" + str);
-
- Fqn<String> fqn = new Fqn<String>(Fqn.fromString(REGION),
InternalConstant.JBOSS_INTERNAL);
- Node<Object, Object> n = cache_.getCache().getRoot().getChild(fqn);
- assertTrue("Internal region node should not exist ",
- n.getChildren() != null);
- }
-
- public void testDynamicRefSwapping() throws Exception
- {
- Person person = createPerson("person/test3", "Joe", 32);
- try
- {
- person.setAge(30);
- List<String> med = person.getMedication();
- assertNull("Medication should be null ", med);
- person.setAge(60);
- med = person.getMedication();
- assertEquals("Medication ", (Object) "Lipitor", (Object)
med.get(0));
- }
- catch (Exception e)
- {
- // should be thrown
- }
- }
-
- public void testMap() throws Exception
- {
- log.info("testMap() ....");
- Person ben = createPerson("person/test1", "Ben Wang", 40);
- assertEquals((Object) "Ben Wang", ben.getName());
- Map<String, String> hobbies = ben.getHobbies();
- if (hobbies == null)
- {
- hobbies = new HashMap<String, String>();
- ben.setHobbies(hobbies);
- // NB: it is neccessary to get hobbies again to get advised version
- hobbies = ben.getHobbies();
- }
- hobbies.put("1", "English");
- hobbies.put("2", "French");
- if (!(hobbies instanceof ClassProxy))
- {
- fail("Hobbies is not an instance of ClassProxy");
- }
-
- hobbies = ben.getHobbies();
- assertEquals("Hobbies size", 2, hobbies.size());
- log.debug("Hobbies is " + hobbies.toString());
- }
-
- public void testMapDetachAttach() throws Exception
- {
- log.info("testMapDetachATtach() ....");
- Person ben = createPerson("person/test1", "Ben Wang", 40);
- assertEquals((Object) "Ben Wang", ben.getName());
- Map<String, String> hobbies = ben.getHobbies();
- if (hobbies == null)
- {
- hobbies = new HashMap<String, String>();
- ben.setHobbies(hobbies);
- // NB: it is neccessary to get hobbies again to get advised version
- hobbies = ben.getHobbies();
- }
- hobbies.put("1", "English");
- hobbies.put("2", "French");
- if (!(hobbies instanceof ClassProxy))
- {
- fail("Hobbies is not an instance of ClassProxy");
- }
-
- hobbies = ben.getHobbies();
- assertEquals("Hobbies size", 2, hobbies.size());
- log.debug("Hobbies is " + hobbies.toString());
-
- cache_.detach("person/test1");
-
- Fqn<String> fqn = new Fqn<String>(Fqn.fromString(REGION),
InternalConstant.JBOSS_INTERNAL);
- Node<Object, Object> n = cache_.getCache().getRoot().getChild(fqn);
- assertTrue("Internal region node should not exist ",
- n.getChildren() != null);
-
- hobbies = ben.getHobbies();
- if ((hobbies instanceof ClassProxy))
- {
- fail("Hobbies should not be an instance of ClassProxy");
- }
-
- cache_.attach("person/1", ben);
-
- }
-
- public void testMap2() throws Throwable
- {
- Person joe = createPerson("person/test5", "Joe Black", 32);
- Map<String, String> hobby = new HashMap<String, String>();
- hobby.put("music", "guitar");
- joe.setHobbies(hobby);
- Object val = joe.getHobbies().get("music");
- assertEquals("guitar", val);
- hobby = joe.getHobbies();
- hobby.put("novel", "English");
- assertEquals("Size of map ", 2, joe.getHobbies().size());
- }
-
- public void testList() throws Throwable
- {
- Person joe = createPerson("person/test6", "Joe", 50);
- List<String> language = new ArrayList<String>();
- language.add("German");
- language.add("English");
- language.add("French");
- joe.setLanguages(language);
-
- assertEquals("Size of language ", 3, joe.getLanguages().size());
- language = joe.getLanguages();
- language.add("Mandarin");
- language.add("Taiwanese");
- language.add("Haka");
- assertEquals("Size of language ", 6, joe.getLanguages().size());
-
- String English = (String) language.get(1);
- assertEquals((Object) "English", English);
- cache_.detach("person/test6");
- }
-
- public void testListDetachAndAttach() throws Throwable
- {
- String id = "person/test6";
- Person joe = new Person();
- List<String> language = new ArrayList<String>();
- language.add("German");
- language.add("English");
- language.add("French");
- joe.setLanguages(language);
-
- cache_.attach(id, joe);
-
- cache_.detach(id);
- joe.getAge();
- cache_.attach(id, joe);
- }
-
- public void testListDetachAndAttach2() throws Throwable
- {
- String id = "person/test6";
- Person joe = createPerson(id, "Joe", 50);
- List<String> language = new ArrayList<String>();
- language.add("German");
- language.add("English");
- language.add("French");
- joe.setLanguages(language);
-
- assertEquals("Size of language ", 3, joe.getLanguages().size());
- language = joe.getLanguages();
- language.add("Mandarin");
- language.add("Taiwanese");
- language.add("Haka");
- assertEquals("Size of language ", 6, joe.getLanguages().size());
-
- String English = (String) language.get(1);
- assertEquals((Object) "English", English);
-
- if (!(language instanceof ClassProxy))
- {
- fail("Language is not an instance of ClassProxy");
- }
-
- cache_.detach(id);
- joe.getAge();
- language = joe.getLanguages();
- if ((language instanceof ClassProxy))
- {
- fail("Language is an instance of ClassProxy");
- }
-
- cache_.attach(id, joe);
- }
-
- public void testSet() throws Throwable
- {
- Person joe = createPerson("person/test7", "Joe", 27);
- Set<String> skill = new HashSet<String>();
- skill.add("Java");
- skill.add("Java");
- skill.add("Java");
- joe.setSkills(skill);
- skill = joe.getSkills();
- assertEquals("Size of skill ", 1, skill.size());
-
- skill.remove("Java");
- assertTrue(skill.isEmpty());
- skill.add("Java");
- skill.add("J2EE");
- skill.add("JBoss");
- assertEquals(new Integer(3), new Integer(skill.size()));
- }
-
- public void testSetDetachAttach() throws Throwable
- {
- String id = "person/test7";
- Person joe = createPerson(id, "Joe", 27);
- Set<String> skill = new HashSet<String>();
- skill.add("Java");
- skill.add("Java");
- skill.add("Java");
- joe.setSkills(skill);
- skill = joe.getSkills();
- assertEquals("Size of skill ", 1, skill.size());
-
- skill.remove("Java");
- assertTrue(skill.isEmpty());
- skill.add("Java");
- skill.add("J2EE");
- skill.add("JBoss");
- assertEquals(new Integer(3), new Integer(skill.size()));
-
- if (!(skill instanceof ClassProxy))
- {
- fail("Skill is not an instance of ClassProxy");
- }
-
- cache_.detach(id);
- joe.getAge();
- skill = joe.getSkills();
- if ((skill instanceof ClassProxy))
- {
- fail("Skill is an instance of ClassProxy");
- }
-
- cache_.attach(id, joe);
- }
-
- public void testInheritance() throws Exception
- {
- Student joe = createStudent("person/joe", "Joe", 32,
"Senior");
- joe.setName("Joe Black");
- assertEquals(joe.getName(), "Joe Black");
- joe.setYear("Junior");
- assertEquals(joe.getYear(), "Junior");
- cache_.detach("person/joe");
- }
-
-
-
-
-
-}
Copied: pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/region/LocalTest.java (from
rev 5129, pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/region/LocalTest.java)
===================================================================
--- pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/region/LocalTest.java
(rev 0)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/region/LocalTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -0,0 +1,374 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at
gnu.org.
+ */
+
+package org.jboss.cache.pojo.region;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNull;
+import static org.testng.AssertJUnit.assertTrue;
+import static org.testng.AssertJUnit.fail;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.aop.proxy.ClassProxy;
+import org.jboss.cache.CacheImpl;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Node;
+import org.jboss.cache.pojo.PojoCache;
+import org.jboss.cache.pojo.PojoCacheFactory;
+import org.jboss.cache.pojo.impl.InternalConstant;
+import org.jboss.cache.pojo.test.Address;
+import org.jboss.cache.pojo.test.Person;
+import org.jboss.cache.pojo.test.Student;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Basic PojoCache test case.
+ *
+ * @author Ben Wang
+ */
+
+@Test(groups = {"functional"})
+public class LocalTest
+{
+ Log log = LogFactory.getLog(org.jboss.cache.pojo.region.LocalTest.class);
+ PojoCache cache_;
+ static final String REGION = "person";
+
+
+ @BeforeMethod(alwaysRun = true)
+ protected void setUp() throws Exception
+ {
+ log.info("setUp() ....");
+ String configFile = "META-INF/local-service.xml";
+ boolean toStart = false;
+ cache_ = PojoCacheFactory.createCache(configFile, toStart);
+ cache_.start();
+ cache_.getCache().getRegion(Fqn.fromString(REGION), true);
+ cache_.getCache().getRegion(Fqn.fromString("RANDOM"), true);
+ }
+
+ @AfterMethod(alwaysRun = true)
+ protected void tearDown() throws Exception
+ {
+ cache_.stop();
+ }
+
+// public void testDummy() {}
+
+ private Person createPerson(String id, String name, int age)
+ {
+ Person p = new Person();
+ p.setName(name);
+ p.setAge(age);
+ Address add = new Address();
+ add.setZip(95123);
+ add.setCity("San Jose");
+ p.setAddress(add);
+ cache_.attach(id, p);
+ return p;
+ }
+
+ private Student createStudent(String id, String name, int age, String grade)
+ {
+ Student p = new Student();
+ p.setName(name);
+ p.setAge(age);
+ p.setYear(grade);
+ Address add = new Address();
+ add.setZip(95123);
+ add.setCity("San Jose");
+ p.setAddress(add);
+ cache_.attach(id, p);
+ return p;
+ }
+
+ public void testSimple() throws Exception
+ {
+ log.info("testSimple() ....");
+ Person p = createPerson("person/test1", "Joe Black", 32);
+ assertEquals((Object) "Joe Black", p.getName());
+
+ assertTrue("Region node should exist ",
+ cache_.getCache().getRoot().hasChild(new Fqn<String>(REGION)));
+ Fqn<String> fqn = new Fqn<String>(Fqn.fromString(REGION),
InternalConstant.JBOSS_INTERNAL);
+ assertTrue("Internal region node should exist ",
+ cache_.getCache().getRoot().hasChild(fqn));
+ //System.out.println("Cache content: "
+((org.jboss.cache.CacheImpl<Object, Object>)cache_.getCache()).printDetails());
+ }
+
+ public void testModification() throws Exception
+ {
+ Person joe = createPerson("person/test2", "Joe", 32);
+ joe.setName("Joe Black");
+ assertEquals(joe.getName(), "Joe Black");
+ cache_.detach("person/test2");
+ }
+
+ public void testRemove() throws Exception
+ {
+ createPerson("person/test3", "Joe", 32);
+ cache_.detach("person/test3");
+
+ //String str = ((CacheImpl<Object, Object>)
cache_.getCache()).printDetails();
+ //System.out.println("**** Details ***/n" + str);
+
+ Fqn<String> fqn = new Fqn<String>(Fqn.fromString(REGION),
InternalConstant.JBOSS_INTERNAL);
+ Node<Object, Object> n = cache_.getCache().getRoot().getChild(fqn);
+ assertTrue("Internal region node should not exist ",
+ n.getChildren() != null);
+ }
+
+ public void testDynamicRefSwapping() throws Exception
+ {
+ Person person = createPerson("person/test3", "Joe", 32);
+ try
+ {
+ person.setAge(30);
+ List<String> med = person.getMedication();
+ assertNull("Medication should be null ", med);
+ person.setAge(60);
+ med = person.getMedication();
+ assertEquals("Medication ", (Object) "Lipitor", (Object)
med.get(0));
+ }
+ catch (Exception e)
+ {
+ // should be thrown
+ }
+ }
+
+ public void testMap() throws Exception
+ {
+ log.info("testMap() ....");
+ Person ben = createPerson("person/test1", "Ben Wang", 40);
+ assertEquals((Object) "Ben Wang", ben.getName());
+ Map<String, String> hobbies = ben.getHobbies();
+ if (hobbies == null)
+ {
+ hobbies = new HashMap<String, String>();
+ ben.setHobbies(hobbies);
+ // NB: it is neccessary to get hobbies again to get advised version
+ hobbies = ben.getHobbies();
+ }
+ hobbies.put("1", "English");
+ hobbies.put("2", "French");
+ if (!(hobbies instanceof ClassProxy))
+ {
+ fail("Hobbies is not an instance of ClassProxy");
+ }
+
+ hobbies = ben.getHobbies();
+ assertEquals("Hobbies size", 2, hobbies.size());
+ log.debug("Hobbies is " + hobbies.toString());
+ }
+
+ public void testMapDetachAttach() throws Exception
+ {
+ log.info("testMapDetachATtach() ....");
+ Person ben = createPerson("person/test1", "Ben Wang", 40);
+ assertEquals((Object) "Ben Wang", ben.getName());
+ Map<String, String> hobbies = ben.getHobbies();
+ if (hobbies == null)
+ {
+ hobbies = new HashMap<String, String>();
+ ben.setHobbies(hobbies);
+ // NB: it is neccessary to get hobbies again to get advised version
+ hobbies = ben.getHobbies();
+ }
+ hobbies.put("1", "English");
+ hobbies.put("2", "French");
+ if (!(hobbies instanceof ClassProxy))
+ {
+ fail("Hobbies is not an instance of ClassProxy");
+ }
+
+ hobbies = ben.getHobbies();
+ assertEquals("Hobbies size", 2, hobbies.size());
+ log.debug("Hobbies is " + hobbies.toString());
+
+ cache_.detach("person/test1");
+
+ Fqn<String> fqn = new Fqn<String>(Fqn.fromString(REGION),
InternalConstant.JBOSS_INTERNAL);
+ Node<Object, Object> n = cache_.getCache().getRoot().getChild(fqn);
+ assertTrue("Internal region node should not exist ",
+ n.getChildren() != null);
+
+ hobbies = ben.getHobbies();
+ if ((hobbies instanceof ClassProxy))
+ {
+ fail("Hobbies should not be an instance of ClassProxy");
+ }
+
+ cache_.attach("person/1", ben);
+
+ }
+
+ public void testMap2() throws Throwable
+ {
+ Person joe = createPerson("person/test5", "Joe Black", 32);
+ Map<String, String> hobby = new HashMap<String, String>();
+ hobby.put("music", "guitar");
+ joe.setHobbies(hobby);
+ Object val = joe.getHobbies().get("music");
+ assertEquals("guitar", val);
+ hobby = joe.getHobbies();
+ hobby.put("novel", "English");
+ assertEquals("Size of map ", 2, joe.getHobbies().size());
+ }
+
+ public void testList() throws Throwable
+ {
+ Person joe = createPerson("person/test6", "Joe", 50);
+ List<String> language = new ArrayList<String>();
+ language.add("German");
+ language.add("English");
+ language.add("French");
+ joe.setLanguages(language);
+
+ assertEquals("Size of language ", 3, joe.getLanguages().size());
+ language = joe.getLanguages();
+ language.add("Mandarin");
+ language.add("Taiwanese");
+ language.add("Haka");
+ assertEquals("Size of language ", 6, joe.getLanguages().size());
+
+ String English = (String) language.get(1);
+ assertEquals((Object) "English", English);
+ cache_.detach("person/test6");
+ }
+
+ public void testListDetachAndAttach() throws Throwable
+ {
+ String id = "person/test6";
+ Person joe = new Person();
+ List<String> language = new ArrayList<String>();
+ language.add("German");
+ language.add("English");
+ language.add("French");
+ joe.setLanguages(language);
+
+ cache_.attach(id, joe);
+
+ cache_.detach(id);
+ joe.getAge();
+ cache_.attach(id, joe);
+ }
+
+ public void testListDetachAndAttach2() throws Throwable
+ {
+ String id = "person/test6";
+ Person joe = createPerson(id, "Joe", 50);
+ List<String> language = new ArrayList<String>();
+ language.add("German");
+ language.add("English");
+ language.add("French");
+ joe.setLanguages(language);
+
+ assertEquals("Size of language ", 3, joe.getLanguages().size());
+ language = joe.getLanguages();
+ language.add("Mandarin");
+ language.add("Taiwanese");
+ language.add("Haka");
+ assertEquals("Size of language ", 6, joe.getLanguages().size());
+
+ String English = (String) language.get(1);
+ assertEquals((Object) "English", English);
+
+ if (!(language instanceof ClassProxy))
+ {
+ fail("Language is not an instance of ClassProxy");
+ }
+
+ cache_.detach(id);
+ joe.getAge();
+ language = joe.getLanguages();
+ if ((language instanceof ClassProxy))
+ {
+ fail("Language is an instance of ClassProxy");
+ }
+
+ cache_.attach(id, joe);
+ }
+
+ public void testSet() throws Throwable
+ {
+ Person joe = createPerson("person/test7", "Joe", 27);
+ Set<String> skill = new HashSet<String>();
+ skill.add("Java");
+ skill.add("Java");
+ skill.add("Java");
+ joe.setSkills(skill);
+ skill = joe.getSkills();
+ assertEquals("Size of skill ", 1, skill.size());
+
+ skill.remove("Java");
+ assertTrue(skill.isEmpty());
+ skill.add("Java");
+ skill.add("J2EE");
+ skill.add("JBoss");
+ assertEquals(new Integer(3), new Integer(skill.size()));
+ }
+
+ public void testSetDetachAttach() throws Throwable
+ {
+ String id = "person/test7";
+ Person joe = createPerson(id, "Joe", 27);
+ Set<String> skill = new HashSet<String>();
+ skill.add("Java");
+ skill.add("Java");
+ skill.add("Java");
+ joe.setSkills(skill);
+ skill = joe.getSkills();
+ assertEquals("Size of skill ", 1, skill.size());
+
+ skill.remove("Java");
+ assertTrue(skill.isEmpty());
+ skill.add("Java");
+ skill.add("J2EE");
+ skill.add("JBoss");
+ assertEquals(new Integer(3), new Integer(skill.size()));
+
+ if (!(skill instanceof ClassProxy))
+ {
+ fail("Skill is not an instance of ClassProxy");
+ }
+
+ cache_.detach(id);
+ joe.getAge();
+ skill = joe.getSkills();
+ if ((skill instanceof ClassProxy))
+ {
+ fail("Skill is an instance of ClassProxy");
+ }
+
+ cache_.attach(id, joe);
+ }
+
+ public void testInheritance() throws Exception
+ {
+ Student joe = createStudent("person/joe", "Joe", 32,
"Senior");
+ joe.setName("Joe Black");
+ assertEquals(joe.getName(), "Joe Black");
+ joe.setYear("Junior");
+ assertEquals(joe.getYear(), "Junior");
+ cache_.detach("person/joe");
+ }
+
+
+
+
+
+}
Deleted:
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/rollback/ReplicatedTxTest.java
===================================================================
---
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/rollback/ReplicatedTxTest.java 2007-11-26
18:16:13 UTC (rev 4776)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/rollback/ReplicatedTxTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -1,393 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at
gnu.org.
- */
-
-package org.jboss.cache.pojo.rollback;
-
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.fail;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.transaction.NotSupportedException;
-import javax.transaction.RollbackException;
-import javax.transaction.SystemException;
-import javax.transaction.UserTransaction;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.config.Configuration.CacheMode;
-import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.pojo.PojoCache;
-import org.jboss.cache.pojo.PojoCacheFactory;
-import org.jboss.cache.pojo.TestingUtil;
-import org.jboss.cache.pojo.test.Person;
-import org.jboss.cache.transaction.DummyTransactionManager;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-/**
- */
-
-@Test(groups = {"functional"})
-public class ReplicatedTxTest
-{
- Log log = LogFactory.getLog(org.jboss.cache.pojo.rollback.ReplicatedTxTest.class);
- PojoCache cache, cache1;
- final String FACTORY = "org.jboss.cache.transaction.DummyContextFactory";
- DummyTransactionManager tx_mgr;
- Throwable t1_ex, t2_ex;
- long start = 0;
-
-
-
- @BeforeMethod(alwaysRun = true)
- protected void setUp() throws Exception
- {
- log.info("setUp() ....");
- boolean toStart = false;
- cache =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
- cache.start();
- cache1 =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
- cache1.start();
-
- System.setProperty(Context.INITIAL_CONTEXT_FACTORY, FACTORY);
-
- tx_mgr = DummyTransactionManager.getInstance();
- t1_ex = t2_ex = null;
- }
-
- @AfterMethod(alwaysRun = true)
- protected void tearDown() throws Exception
- {
- cache.stop();
- cache1.stop();
-
- DummyTransactionManager.destroy();
- }
-
-// public void testDummy() {}
-
- UserTransaction getTransaction() throws SystemException, NotSupportedException,
NamingException
- {
- Properties prop = new Properties();
- prop.put(Context.INITIAL_CONTEXT_FACTORY,
- "org.jboss.cache.transaction.DummyContextFactory");
- return (UserTransaction) new
InitialContext(prop).lookup("UserTransaction");
- }
-
- private Person createPerson(String id, String name, int age)
- {
- Person p = new Person();
- p.setName(name);
- p.setAge(age);
- return p;
- }
-
- public void testSimple() throws Exception
- {
- log.info("testSimple() ....");
- UserTransaction tx = getTransaction();
- tx.begin();
- Person p = createPerson("/person/test1", "Harald Gliebe", 32);
- cache.attach("/person/test1", p);
-
- tx.commit();
- tx.begin();
- p.setName("Benoit");
- tx.commit();
- Person p1 = (Person) cache1.find("/person/test1");
- assertEquals("Benoit", p.getName());
- assertEquals("Benoit", p1.getName());
- tx.begin();
- p1.setAge(61);
- tx.commit();
- assertEquals(61, p.getAge());
- assertEquals(61, p1.getAge());
- }
-
- /**
- * Concurrent puts (whole POJO) from the same cache instance (different threads) with
rollback.
- */
- public void testConcurrentPuts() throws Exception
- {
- Thread t1 = new Thread()
- {
- public void run()
- {
- try
- {
- Person p = createPerson("/person/test6", "p6", 50);
- List<String> lang = new ArrayList<String>();
- lang.add("German");
- p.setLanguages(lang);
- UserTransaction tx = getTransaction();
- tx.begin();
- cache.attach("/person/test6", p);
- TestingUtil.sleepThread(17000);
- tx.commit();
- }
- catch (RollbackException rollback)
- {
- ;
- }
- catch (Exception ex)
- {
- t1_ex = ex;
- }
- }
- };
-
- Thread t2 = new Thread()
- {
- public void run()
- {
- UserTransaction tx = null;
- Person p = createPerson("/person/test6", "p6", 50);
- try
- {
- TestingUtil.sleepThread(1000); // give Thread1 time to createPerson
- List<String> lang = new ArrayList<String>();
- lang.add("German");
- p.setLanguages(lang);
- tx = getTransaction();
- tx.begin();
- cache.attach("/person/test6", p);
- tx.commit();
- }
- catch (RollbackException rollback)
- {
- ;
- }
- catch (Exception ex)
- {
- try
- {
- tx.rollback();
- }
- catch (SystemException e)
- {
- e.printStackTrace();
- t2_ex = e;
- }
- }
-
- cache.attach("/person/test6", p);
-
- }
- };
-
- t1.start();
- t2.start();
-
- t1.join();
- t2.join();
-
- // t2 should rollback due to timeout while t2 should succeed
- if (t2_ex != null)
- fail("Thread1 failed: " + t2_ex);
- if (t1_ex != null)
- fail("Thread2 failed: " + t1_ex);
-
- int size = ((Person) cache.find("/person/test6")).getLanguages().size();
- assertEquals("number of languages", 1, size);
- size = ((Person) cache1.find("/person/test6")).getLanguages().size();
- assertEquals("number of languages", 1, size);
- }
-
- /**
- * Concurrent puts from the same cache instance (different threads) with rollback.
- */
- public void testConcurrentPuts1() throws Exception
- {
- Thread t1 = new Thread()
- {
- public void run()
- {
- try
- {
- List<String> lang = ((Person)
cache.find("/person/test6")).getLanguages();
- UserTransaction tx = getTransaction();
- tx.begin();
- lang.add("German");
- TestingUtil.sleepThread(17000);
- tx.commit();
- }
- catch (RollbackException rollback)
- {
- ;
- }
- catch (Exception ex)
- {
- t1_ex = ex;
- }
- }
- };
-
- Thread t2 = new Thread()
- {
- public void run()
- {
- UserTransaction tx = null;
- try
- {
- TestingUtil.sleepThread(1000); // give Thread1 time to createPerson
- List<String> lang = ((Person)
cache1.find("/person/test6")).getLanguages();
- tx = getTransaction();
- tx.begin();
- lang.add("English");
- tx.commit();
- }
- catch (RollbackException rollback)
- {
- ;
- }
- catch (Exception ex)
- {
- try
- {
- tx.rollback();
- }
- catch (SystemException e)
- {
- e.printStackTrace();
- t2_ex = e;
- }
- }
- }
- };
-
- Person p = createPerson("/person/test6", "p6", 50);
- cache.attach("/person/test6", p);
- List<String> lang = new ArrayList<String>();
- lang.add("German");
- p.setLanguages(lang);
-
- t1.start();
- t2.start();
-
- t1.join();
- t2.join();
-
- // t2 should rollback due to timeout while t2 should succeed
- if (t2_ex != null)
- fail("Thread1 failed: " + t2_ex);
- if (t1_ex != null)
- fail("Thread2 failed: " + t1_ex);
-
- int size = ((Person) cache.find("/person/test6")).getLanguages().size();
- assertEquals("number of languages", 2, size);
- size = ((Person) cache1.find("/person/test6")).getLanguages().size();
- assertEquals("number of languages", 2, size);
- }
-
- /**
- * Concurrent puts from the different cache instances (different threads) with
rollback.
- */
- public void testConcurrentPuts2() throws Exception
- {
- Thread t1 = new Thread()
- {
- public void run()
- {
- try
- {
- List<String> lang = ((Person)
cache.find("/person/test6")).getLanguages();
- UserTransaction tx = getTransaction();
- tx.begin();
- lang.add("German");
- TestingUtil.sleepThread(17000);
- tx.commit();
- }
- catch (RollbackException rollback)
- {
- ;
- }
- catch (Exception ex)
- {
- t1_ex = ex;
- }
- }
- };
-
- Thread t2 = new Thread()
- {
- public void run()
- {
- UserTransaction tx = null;
- try
- {
- TestingUtil.sleepThread(1000); // give Thread1 time to createPerson
- List<String> lang = ((Person)
cache.find("/person/test6")).getLanguages();
- tx = getTransaction();
- tx.begin();
- lang.add("English");
- tx.commit();
- }
- catch (RollbackException rollback)
- {
- ;
- }
- catch (Exception ex)
- {
- try
- {
- tx.rollback();
- }
- catch (SystemException e)
- {
- e.printStackTrace();
- t2_ex = e;
- }
- }
- }
- };
-
- Person p = createPerson("/person/test6", "p6", 50);
- cache.attach("/person/test6", p);
- List<String> lang = new ArrayList<String>();
- lang.add("German");
- p.setLanguages(lang);
-
- t1.start();
- t2.start();
-
- t1.join();
- t2.join();
-
- // t2 should rollback due to timeout while t2 should succeed
- if (t2_ex != null)
- fail("Thread1 failed: " + t2_ex);
- if (t1_ex != null)
- fail("Thread2 failed: " + t1_ex);
-
- int size = ((Person) cache.find("/person/test6")).getLanguages().size();
- assertEquals("number of languages", 2, size);
- size = ((Person) cache1.find("/person/test6")).getLanguages().size();
- assertEquals("number of languages", 2, size);
- }
-
- void log(String s)
- {
- long now;
- if (start == 0)
- start = System.currentTimeMillis();
- now = System.currentTimeMillis();
-
- System.out.println("[" + Thread.currentThread().getName() + "]
[" + (now - start) + "] " + s);
- }
-
-
-
-
-
-}
Copied:
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/rollback/ReplicatedTxTest.java
(from rev 5129,
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/rollback/ReplicatedTxTest.java)
===================================================================
--- pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/rollback/ReplicatedTxTest.java
(rev 0)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/rollback/ReplicatedTxTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -0,0 +1,393 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at
gnu.org.
+ */
+
+package org.jboss.cache.pojo.rollback;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+import javax.transaction.UserTransaction;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.pojo.PojoCache;
+import org.jboss.cache.pojo.PojoCacheFactory;
+import org.jboss.cache.pojo.test.Person;
+import org.jboss.cache.transaction.DummyTransactionManager;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ */
+
+@Test(groups = {"functional"})
+public class ReplicatedTxTest
+{
+ Log log = LogFactory.getLog(org.jboss.cache.pojo.rollback.ReplicatedTxTest.class);
+ PojoCache cache, cache1;
+ final String FACTORY = "org.jboss.cache.transaction.DummyContextFactory";
+ DummyTransactionManager tx_mgr;
+ Throwable t1_ex, t2_ex;
+ long start = 0;
+
+
+
+ @BeforeMethod(alwaysRun = true)
+ protected void setUp() throws Exception
+ {
+ log.info("setUp() ....");
+ boolean toStart = false;
+ cache =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
+ cache.start();
+ cache1 =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
+ cache1.start();
+
+ System.setProperty(Context.INITIAL_CONTEXT_FACTORY, FACTORY);
+
+ tx_mgr = DummyTransactionManager.getInstance();
+ t1_ex = t2_ex = null;
+ }
+
+ @AfterMethod(alwaysRun = true)
+ protected void tearDown() throws Exception
+ {
+ cache.stop();
+ cache1.stop();
+
+ DummyTransactionManager.destroy();
+ }
+
+// public void testDummy() {}
+
+ UserTransaction getTransaction() throws SystemException, NotSupportedException,
NamingException
+ {
+ Properties prop = new Properties();
+ prop.put(Context.INITIAL_CONTEXT_FACTORY,
+ "org.jboss.cache.transaction.DummyContextFactory");
+ return (UserTransaction) new
InitialContext(prop).lookup("UserTransaction");
+ }
+
+ private Person createPerson(String id, String name, int age)
+ {
+ Person p = new Person();
+ p.setName(name);
+ p.setAge(age);
+ return p;
+ }
+
+ public void testSimple() throws Exception
+ {
+ log.info("testSimple() ....");
+ UserTransaction tx = getTransaction();
+ tx.begin();
+ Person p = createPerson("/person/test1", "Harald Gliebe", 32);
+ cache.attach("/person/test1", p);
+
+ tx.commit();
+ tx.begin();
+ p.setName("Benoit");
+ tx.commit();
+ Person p1 = (Person) cache1.find("/person/test1");
+ assertEquals("Benoit", p.getName());
+ assertEquals("Benoit", p1.getName());
+ tx.begin();
+ p1.setAge(61);
+ tx.commit();
+ assertEquals(61, p.getAge());
+ assertEquals(61, p1.getAge());
+ }
+
+ /**
+ * Concurrent puts (whole POJO) from the same cache instance (different threads) with
rollback.
+ */
+ public void testConcurrentPuts() throws Exception
+ {
+ Thread t1 = new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ Person p = createPerson("/person/test6", "p6", 50);
+ List<String> lang = new ArrayList<String>();
+ lang.add("German");
+ p.setLanguages(lang);
+ UserTransaction tx = getTransaction();
+ tx.begin();
+ cache.attach("/person/test6", p);
+ TestingUtil.sleepThread(17000);
+ tx.commit();
+ }
+ catch (RollbackException rollback)
+ {
+ ;
+ }
+ catch (Exception ex)
+ {
+ t1_ex = ex;
+ }
+ }
+ };
+
+ Thread t2 = new Thread()
+ {
+ public void run()
+ {
+ UserTransaction tx = null;
+ Person p = createPerson("/person/test6", "p6", 50);
+ try
+ {
+ TestingUtil.sleepThread(1000); // give Thread1 time to createPerson
+ List<String> lang = new ArrayList<String>();
+ lang.add("German");
+ p.setLanguages(lang);
+ tx = getTransaction();
+ tx.begin();
+ cache.attach("/person/test6", p);
+ tx.commit();
+ }
+ catch (RollbackException rollback)
+ {
+ ;
+ }
+ catch (Exception ex)
+ {
+ try
+ {
+ tx.rollback();
+ }
+ catch (SystemException e)
+ {
+ e.printStackTrace();
+ t2_ex = e;
+ }
+ }
+
+ cache.attach("/person/test6", p);
+
+ }
+ };
+
+ t1.start();
+ t2.start();
+
+ t1.join();
+ t2.join();
+
+ // t2 should rollback due to timeout while t2 should succeed
+ if (t2_ex != null)
+ fail("Thread1 failed: " + t2_ex);
+ if (t1_ex != null)
+ fail("Thread2 failed: " + t1_ex);
+
+ int size = ((Person) cache.find("/person/test6")).getLanguages().size();
+ assertEquals("number of languages", 1, size);
+ size = ((Person) cache1.find("/person/test6")).getLanguages().size();
+ assertEquals("number of languages", 1, size);
+ }
+
+ /**
+ * Concurrent puts from the same cache instance (different threads) with rollback.
+ */
+ public void testConcurrentPuts1() throws Exception
+ {
+ Thread t1 = new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ List<String> lang = ((Person)
cache.find("/person/test6")).getLanguages();
+ UserTransaction tx = getTransaction();
+ tx.begin();
+ lang.add("German");
+ TestingUtil.sleepThread(17000);
+ tx.commit();
+ }
+ catch (RollbackException rollback)
+ {
+ ;
+ }
+ catch (Exception ex)
+ {
+ t1_ex = ex;
+ }
+ }
+ };
+
+ Thread t2 = new Thread()
+ {
+ public void run()
+ {
+ UserTransaction tx = null;
+ try
+ {
+ TestingUtil.sleepThread(1000); // give Thread1 time to createPerson
+ List<String> lang = ((Person)
cache1.find("/person/test6")).getLanguages();
+ tx = getTransaction();
+ tx.begin();
+ lang.add("English");
+ tx.commit();
+ }
+ catch (RollbackException rollback)
+ {
+ ;
+ }
+ catch (Exception ex)
+ {
+ try
+ {
+ tx.rollback();
+ }
+ catch (SystemException e)
+ {
+ e.printStackTrace();
+ t2_ex = e;
+ }
+ }
+ }
+ };
+
+ Person p = createPerson("/person/test6", "p6", 50);
+ cache.attach("/person/test6", p);
+ List<String> lang = new ArrayList<String>();
+ lang.add("German");
+ p.setLanguages(lang);
+
+ t1.start();
+ t2.start();
+
+ t1.join();
+ t2.join();
+
+ // t2 should rollback due to timeout while t2 should succeed
+ if (t2_ex != null)
+ fail("Thread1 failed: " + t2_ex);
+ if (t1_ex != null)
+ fail("Thread2 failed: " + t1_ex);
+
+ int size = ((Person) cache.find("/person/test6")).getLanguages().size();
+ assertEquals("number of languages", 2, size);
+ size = ((Person) cache1.find("/person/test6")).getLanguages().size();
+ assertEquals("number of languages", 2, size);
+ }
+
+ /**
+ * Concurrent puts from the different cache instances (different threads) with
rollback.
+ */
+ public void testConcurrentPuts2() throws Exception
+ {
+ Thread t1 = new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ List<String> lang = ((Person)
cache.find("/person/test6")).getLanguages();
+ UserTransaction tx = getTransaction();
+ tx.begin();
+ lang.add("German");
+ TestingUtil.sleepThread(17000);
+ tx.commit();
+ }
+ catch (RollbackException rollback)
+ {
+ ;
+ }
+ catch (Exception ex)
+ {
+ t1_ex = ex;
+ }
+ }
+ };
+
+ Thread t2 = new Thread()
+ {
+ public void run()
+ {
+ UserTransaction tx = null;
+ try
+ {
+ TestingUtil.sleepThread(1000); // give Thread1 time to createPerson
+ List<String> lang = ((Person)
cache.find("/person/test6")).getLanguages();
+ tx = getTransaction();
+ tx.begin();
+ lang.add("English");
+ tx.commit();
+ }
+ catch (RollbackException rollback)
+ {
+ ;
+ }
+ catch (Exception ex)
+ {
+ try
+ {
+ tx.rollback();
+ }
+ catch (SystemException e)
+ {
+ e.printStackTrace();
+ t2_ex = e;
+ }
+ }
+ }
+ };
+
+ Person p = createPerson("/person/test6", "p6", 50);
+ cache.attach("/person/test6", p);
+ List<String> lang = new ArrayList<String>();
+ lang.add("German");
+ p.setLanguages(lang);
+
+ t1.start();
+ t2.start();
+
+ t1.join();
+ t2.join();
+
+ // t2 should rollback due to timeout while t2 should succeed
+ if (t2_ex != null)
+ fail("Thread1 failed: " + t2_ex);
+ if (t1_ex != null)
+ fail("Thread2 failed: " + t1_ex);
+
+ int size = ((Person) cache.find("/person/test6")).getLanguages().size();
+ assertEquals("number of languages", 2, size);
+ size = ((Person) cache1.find("/person/test6")).getLanguages().size();
+ assertEquals("number of languages", 2, size);
+ }
+
+ void log(String s)
+ {
+ long now;
+ if (start == 0)
+ start = System.currentTimeMillis();
+ now = System.currentTimeMillis();
+
+ System.out.println("[" + Thread.currentThread().getName() + "]
[" + (now - start) + "] " + s);
+ }
+
+
+
+
+
+}
Deleted:
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/statetransfer/ReplicatedTest.java
===================================================================
---
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/statetransfer/ReplicatedTest.java 2007-11-26
18:16:13 UTC (rev 4776)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/statetransfer/ReplicatedTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -1,99 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.jboss.cache.pojo.statetransfer;
-
-import static org.testng.AssertJUnit.assertEquals;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheImpl;
-import org.jboss.cache.config.Configuration.CacheMode;
-import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.pojo.PojoCache;
-import org.jboss.cache.pojo.PojoCacheFactory;
-import org.jboss.cache.pojo.test.Person;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-/**
- * Simple replicated test for state transfer
- *
- * @author Ben Wang
- */
-@Test(groups = {"functional"})
-public class ReplicatedTest
-{
- Log log = LogFactory.getLog(ReplicatedTest.class);
- PojoCache cache, cache1;
-
-
-
- @BeforeMethod(alwaysRun = true)
- protected void setUp() throws Exception
- {
- log.info("setUp() ....");
- }
-
- @AfterMethod(alwaysRun = true)
- protected void tearDown() throws Exception
- {
- cache.stop();
- cache1.stop();
- }
-
-// public void testDummy() {}
-
- private Person createPerson(String id, String name, int age)
- {
- Person p = new Person();
- p.setName(name);
- p.setAge(age);
- cache.attach(id, p);
- return p;
- }
-
- public void testSimple() throws Exception
- {
- boolean toStart = true;
- cache =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
- Person ben = createPerson("/person/test1", "Ben Wang", 40);
-
- System.out.println("\n*** I ***");
- System.out.println(((CacheImpl<Object, Object>)
cache.getCache()).printDetails());
- cache1 =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
- cache1.start();
-
- System.out.println("\n*** II ***");
- System.out.println(((CacheImpl<Object, Object>)
cache1.getCache()).printDetails());
-
- log.info("testSimple() ....");
- assertEquals("Ben Wang", ben.getName());
- assertEquals("Ben Wang", ((Person)
cache1.find("/person/test1")).getName());
- cache.detach("/person/test1");
- }
-
-
-
-
-}
Copied:
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/statetransfer/ReplicatedTest.java
(from rev 5129,
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/statetransfer/ReplicatedTest.java)
===================================================================
---
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/statetransfer/ReplicatedTest.java
(rev 0)
+++
pojo/tags/2.1.0.CR3/src/test/java/org/jboss/cache/pojo/statetransfer/ReplicatedTest.java 2008-01-16
00:43:28 UTC (rev 5140)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.jboss.cache.pojo.statetransfer;
+
+import static org.testng.AssertJUnit.assertEquals;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheImpl;
+import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.pojo.PojoCache;
+import org.jboss.cache.pojo.PojoCacheFactory;
+import org.jboss.cache.pojo.test.Person;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Simple replicated test for state transfer
+ *
+ * @author Ben Wang
+ */
+@Test(groups = {"functional"})
+public class ReplicatedTest
+{
+ Log log = LogFactory.getLog(ReplicatedTest.class);
+ PojoCache cache, cache1;
+
+
+
+ @BeforeMethod(alwaysRun = true)
+ protected void setUp() throws Exception
+ {
+ log.info("setUp() ....");
+ }
+
+ @AfterMethod(alwaysRun = true)
+ protected void tearDown() throws Exception
+ {
+ cache.stop();
+ cache1.stop();
+ }
+
+// public void testDummy() {}
+
+ private Person createPerson(String id, String name, int age)
+ {
+ Person p = new Person();
+ p.setName(name);
+ p.setAge(age);
+ cache.attach(id, p);
+ return p;
+ }
+
+ public void testSimple() throws Exception
+ {
+ boolean toStart = true;
+ cache =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
+ Person ben = createPerson("/person/test1", "Ben Wang", 40);
+
+ //System.out.println("\n*** I ***");
+ //System.out.println(((CacheImpl<Object, Object>)
cache.getCache()).printDetails());
+ cache1 =
PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
toStart);
+ cache1.start();
+
+ //System.out.println("\n*** II ***");
+ //System.out.println(((CacheImpl<Object, Object>)
cache1.getCache()).printDetails());
+
+ log.info("testSimple() ....");
+ assertEquals("Ben Wang", ben.getName());
+ assertEquals("Ben Wang", ((Person)
cache1.find("/person/test1")).getName());
+ cache.detach("/person/test1");
+ }
+
+
+
+
+}