You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by sm...@apache.org on 2007/06/08 18:35:10 UTC
svn commit: r545554 [10/13] - in
/harmony/enhanced/buildtest/branches/2.0/tests/reliability: ./ run/ src/
src/java/ src/java/org/ src/java/org/apache/ src/java/org/apache/harmony/
src/java/org/apache/harmony/test/ src/java/org/apache/harmony/test/relia...
Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/getAvailableLocals_RBC.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/getAvailableLocals_RBC.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/getAvailableLocals_RBC.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/getAvailableLocals_RBC.java Fri Jun 8 09:34:52 2007
@@ -0,0 +1,159 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author Olessia Salmina
+ */
+
+package org.apache.harmony.test.reliability.api.text;
+
+
+import org.apache.harmony.test.reliability.share.Test;
+import java.util.*;
+import java.text.*;
+
+
+/**
+ * Goal: find resource leaks or intermittent failures or java.text.RuleBasedCollator cache problems.
+ * Test creates RuleBasedCollator, using the set of rules, which is obtained as an integration
+ * of rules for available locales.
+ *
+ * The test does:
+ * 1. Reads parameters, which are:
+ * param[0] - number of threads to be run in parallel
+ * param[1] - number of iterations in each thread.
+ *
+ * 2. Gets all available locales via Locale.getAvailableLocales().
+ * 3. Creates RuleBasedCollator for next in turn locale via
+ * (RuleBasedCollator) Collator.getInstance(Locale ...)
+ * 4. Get rule for this RuleBasedCollator using method getRules().
+ * 5. Add obtained rules to finish RuleBasedCollator rules set.
+ * 6. Runs System.gc().
+ */
+
+public class getAvailableLocals_RBC extends Test{
+
+ public static int callSystemGC = 1;
+ public static int NUMBER_OF_ITERATIONS = 100;
+ public int numThreads = 10;
+ public int[] statuses;
+
+ public static void main(String[] args) {
+ System.exit(new getAvailableLocals_RBC().test(args));
+ }
+
+ public int test(String[] params) {
+ parseParams(params);
+
+ Thread[] t = new Thread[numThreads];
+
+ statuses = new int[t.length];
+
+ for (int i = 0; i < t.length; i++) {
+ t[i] = new Thread(new RuleBasedCollatorRun(i, this));
+ t[i].start();
+ //log.add("Thread " + i + " started");
+ }
+
+ // Correctly wait for all threads to finish
+
+ for (int i = 0; i < t.length; ++i) {
+ try {
+ t[i].join();
+ //log.add("Thread " + i + ": joined() ");
+
+ } catch (InterruptedException ie) {
+ return fail("interruptedException while join() of thread #" + i);
+ }
+ }
+
+ // For each thread check whether operations/checks PASSed in the thread
+
+ for (int i = 0; i < statuses.length; ++i) {
+ if (statuses[i] != Status.PASS) {
+ return fail("thread #" + i + " returned not PASS status");
+ }
+ //log.add("Status of thread " + i + ": is PASS");
+ }
+
+ return pass("OK");
+ }
+
+ public void parseParams(String[] params) {
+ if (params.length >= 1) {
+ numThreads = Integer.parseInt(params[0]);
+ }
+ if (params.length >= 2) {
+ NUMBER_OF_ITERATIONS = Integer.parseInt(params[1]);
+ }
+ }
+
+}
+
+
+class RuleBasedCollatorRun implements Runnable {
+ public int id;
+ public getAvailableLocals_RBC base;
+
+ public RuleBasedCollatorRun(int id, getAvailableLocals_RBC base) {
+
+ this.id = id;
+ this.base = base;
+ }
+
+ public void run() {
+ for (int k = 0; k < getAvailableLocals_RBC.NUMBER_OF_ITERATIONS; k++) {
+ //base.log.add("Iteration number "+k);
+ Locale[] allLocales = Locale.getAvailableLocales();
+ Thread.yield();
+
+ RuleBasedCollator finishRBC = (RuleBasedCollator) Collator
+ .getInstance();
+
+ //base.log.add("Default Locale "+(Locale.getDefault()).toString());
+ Thread.yield();
+
+ for (int i = 0; i < allLocales.length; i++) {
+ RuleBasedCollator someRBC = (RuleBasedCollator) Collator
+ .getInstance(allLocales[i]);
+ Thread.yield();
+
+ //base.log.add("Added rules for Locale "+(allLocales[i]).toString());
+ Thread.yield();
+
+ String finishRBC_Rules = finishRBC.getRules();
+ Thread.yield();
+
+ String someRBC_Rules = someRBC.getRules();
+ Thread.yield();
+
+ if((i % 8) == 0){
+ try {
+ finishRBC = new RuleBasedCollator(finishRBC_Rules
+ + someRBC_Rules);
+ } catch (ParseException e) {
+ // e.printStackTrace();
+ }
+ }
+ }
+ if (getAvailableLocals_RBC.callSystemGC != 0){
+ System.gc();
+ }
+ }
+ base.statuses[id] = Status.PASS;
+ }
+}
\ No newline at end of file
Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/getAvailableLocals_RBC.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/getSentenceInstance.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/getSentenceInstance.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/getSentenceInstance.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/getSentenceInstance.java Fri Jun 8 09:34:52 2007
@@ -0,0 +1,217 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author Olessia Salmina
+ */
+
+package org.apache.harmony.test.reliability.api.text;
+
+import org.apache.harmony.test.reliability.share.Test;
+import java.util.*;
+import java.text.*;
+
+
+/**
+ * Goal:
+ * find resource leaks (or intermittent failures, or cache problems),
+ * connected with use of following java.text.BreakIterator methods:
+ * - BreakIterator.getSentenceInstance(Locale)
+ * - BreakIterator.setText(String)
+ * - BreakIterator.next()
+ *
+ * NOTE: test does not check, that sentence-breaks are set correctly.
+ *
+ * The test does:
+ *
+ * 1. Reads parameters, which are:
+ * param[0] - number of threads to be run in parallel
+ * param[1] - number of iterations in each thread
+ *
+ * 2. Obtains array of sinrings with different sentances and different punctuation marks.
+ * 3. Parse these strings in a cycle.
+ * 4. Runs System.gc()
+ */
+
+
+
+public class getSentenceInstance extends Test {
+
+ public int callSystemGC = 1;
+
+ public int NUMBER_OF_ITERATIONS = 100;
+
+ public int numThreads = 10;
+
+ public int[] statuses;
+
+ public static void main(String[] args) {
+ System.exit(new getSentenceInstance ().test(args));
+ }
+
+
+ public int test(String[] params) {
+
+ parseParams(params);
+
+ // Start 'numThreads' threads each reading from file, inflating/deflating
+
+ Thread[] t = new Thread[numThreads];
+
+ statuses = new int[t.length];
+
+ for (int i = 0; i < t.length; i++) {
+ t[i] = new Thread(new SentenceInstanceRunner(i, this));
+ t[i].start();
+ //log.add("Thread " + i + " started");
+ }
+
+ // Correctly wait for all threads to finish
+
+ for (int i = 0; i < t.length; ++i){
+ try {
+ t[i].join();
+ //log.add("Thread " + i + ": joined() ");
+
+ } catch (InterruptedException ie){
+ return fail("interruptedException while join() of thread #" + i);
+ }
+ }
+
+ // For each thread check whether operations/checks PASSed in the thread
+
+ for (int i = 0; i < statuses.length; ++i){
+ if (statuses[i] != Status.PASS){
+ return fail("thread #" + i + " returned not PASS status");
+ }
+ //log.add("Status of thread " + i + ": is PASS");
+ }
+
+ return pass("OK");
+ }
+
+
+ public void parseParams(String[] params) {
+
+ if (params.length >= 1) {
+ numThreads = Integer.parseInt(params[0]);
+ }
+
+ if (params.length >= 2) {
+ NUMBER_OF_ITERATIONS = Integer.parseInt(params[1]);
+ }
+
+ }
+
+}
+
+class SentenceInstanceRunner implements Runnable {
+
+ public int id;
+ public getSentenceInstance base;
+
+ public SentenceInstanceRunner(int id, getSentenceInstance base) {
+ this.id = id;
+ this.base = base;
+ }
+
+
+
+ public void run() {
+ int k = 0;
+ while (k++ < base.NUMBER_OF_ITERATIONS) {
+
+ Thread.yield();
+
+ String[] toParse = new String[14];
+ toParse[0] = "\"What\'s the matter?..\"";
+ toParse[1] = "I was pretty shaken up!..";
+ toParse[2] = "\"I was pretty shaken up!..\"";
+ toParse[3] = "\"I was pretty shaken up,\" - he sad.";
+ toParse[4] = "\"I was pretty shaken up.\" - he sad.";
+ toParse[5] = "\"I was pretty shaken up...\" - he sad.";
+ toParse[6] = "\"I was pretty shaken up!..\" - he sad.";
+ toParse[7] = "W3C\'s easy-to-use HTML validation service, based on ... an SGML parser.";
+ toParse[8] = "Published Wednesday 21st December 2006 11:58 GMT";
+ toParse[9] = "I.e. is the abbreviation for a two-word Latin term, id est. "
+ + "Translated word for word, id est means\"that is.\"";
+ toParse[10] = "This specification defines the HyperText Markup Language (HTML),"
+ + "version 4.0, the publishing language...";
+ toParse[11] = "Published 2005-08-10";
+ toParse[12] = "Number pi is approximately equal to 3.14.";
+ toParse[13] = "Number pi is approximately equal to 3.14";
+
+ for (int i = 0; i < toParse.length; i++) {
+
+ SIterator_Marker SI = new SIterator_Marker(toParse[i]);
+
+ Thread.yield();
+
+ int boundary = SI.sentenceIterator.first();
+
+ while (boundary != BreakIterator.DONE) {
+ SI.markers.setCharAt(boundary, '^');
+ boundary = SI.sentenceIterator.next();
+ Thread.yield();
+ } //while
+
+ //base.log.add(" " + SI.ScanStr + "\r\n"
+ // + "-----------------------" + SI.markers);
+ //base.log.add(" "+SI.markers);
+
+ Thread.yield();
+
+ }//for
+
+ if (base.callSystemGC != 0) {
+ System.gc();
+ }
+
+ }//while
+ base.statuses[id] = Status.PASS;
+ }
+}
+
+ //class Status {
+ // public static final int FAIL = -10;
+ // public static final int PASS = 10;
+ //}
+
+class SIterator_Marker {
+ public BreakIterator sentenceIterator;
+
+ public StringBuffer markers;
+
+ public String ScanStr;
+
+ public SIterator_Marker(String toScan) {
+ Locale currentLocale = new Locale("en", "US");
+ sentenceIterator = BreakIterator.getSentenceInstance(currentLocale);
+
+ markers = new StringBuffer();
+
+ sentenceIterator.setText(toScan);
+
+ markers.setLength(toScan.length() + 1);
+ for (int j = 0; j < markers.length(); j++) {
+ markers.setCharAt(j, ' ');
+
+ ScanStr = new String(toScan);
+ }
+
+ }
+}
\ No newline at end of file
Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/getSentenceInstance.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/getSentenceInstance_check.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/getSentenceInstance_check.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/getSentenceInstance_check.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/getSentenceInstance_check.java Fri Jun 8 09:34:52 2007
@@ -0,0 +1,286 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author Olessia Salmina
+ */
+
+package org.apache.harmony.test.reliability.api.text;
+
+import org.apache.harmony.test.reliability.share.Test;
+import java.util.*;
+import java.text.*;
+
+
+/**
+ * Goal:
+ * 1) find resource leaks (or intermittent failures, or cache problems),
+ * connected with use of following java.text.BreakIterator methods:
+ * - BreakIterator.getSentenceInstance(Locale)
+ * - BreakIterator.setText(String)
+ * - BreakIterator.next()
+ *
+ * 2) check, that sentence-breaks are set correctly.
+ *
+ * The test does:
+ *
+ * 1. Reads parameters, which are:
+ * param[0] - number of threads to be run in parallel
+ * param[1] - number of iterations in each thread
+ *
+ * 2. Obtains array of sinrings with different sentances and different punctuation marks.
+ * 3. Parse these strings and comapre the result of parsing with f standard.
+ * 4. Runs System.gc()
+ */
+
+
+public class getSentenceInstance_check extends Test {
+
+ public int callSystemGC = 1;
+
+ public int NUMBER_OF_ITERATIONS = 100;
+
+ public int numThreads = 10;
+
+ public int[] statuses;
+
+ public static void main(String[] args) {
+ System.exit(new getSentenceInstance_check().test(args));
+ }
+
+
+ public int test(String[] params) {
+
+ parseParams(params);
+
+ // Start 'numThreads' threads each reading from file, inflating/deflating
+
+ Thread[] t = new Thread[numThreads];
+
+ statuses = new int[t.length];
+
+ for (int i = 0; i < t.length; i++) {
+ t[i] = new Thread(new SentenceInstanceChRunner(i, this));
+ t[i].start();
+ //log.add("Thread " + i + " started");
+ }
+
+ // Correctly wait for all threads to finish
+
+ for (int i = 0; i < t.length; ++i){
+ try {
+ t[i].join();
+ //log.add("Thread " + i + ": joined() ");
+
+ } catch (InterruptedException ie){
+ return fail("interruptedException while join() of thread #" + i);
+ }
+ }
+
+ // For each thread check whether operations/checks PASSed in the thread
+
+ for (int i = 0; i < statuses.length; ++i){
+ if (statuses[i] != Status.PASS){
+ return fail("thread #" + i + " returned not PASS status");
+ }
+ //log.add("Status of thread " + i + ": is PASS");
+ }
+
+ return pass("OK");
+ }
+
+
+ public void parseParams(String[] params) {
+
+ if (params.length >= 1) {
+ numThreads = Integer.parseInt(params[0]);
+ }
+
+ if (params.length >= 2) {
+ NUMBER_OF_ITERATIONS = Integer.parseInt(params[1]);
+ }
+
+ }
+
+}
+
+class SentenceInstanceChRunner implements Runnable {
+
+ public int id;
+
+ public getSentenceInstance_check base;
+
+ public SentenceInstanceChRunner(int id, getSentenceInstance_check base) {
+ this.id = id;
+ this.base = base;
+ }
+
+ public void run() {
+ int k = 0;
+ while (k++ < base.NUMBER_OF_ITERATIONS) {
+
+ Thread.yield();
+
+ String[] toParse = new String[14];
+ toParse[0] = "\"What\'s the matter?..\"";
+ toParse[1] = "I was pretty shaken up!..";
+ toParse[2] = "\"I was pretty shaken up!..\"";
+ toParse[3] = "\"I was pretty shaken up,\" - he sad.";
+ toParse[4] = "\"I was pretty shaken up.\" - he sad.";
+ toParse[5] = "\"I was pretty shaken up...\" - he sad.";
+ toParse[6] = "\"I was pretty shaken up!..\" - he sad.";
+ toParse[7] = "W3C\'s easy-to-use HTML validation service, based on ... an SGML parser.";
+ toParse[8] = "Published Wednesday 21st December 2006 11:58 GMT";
+ toParse[9] = "I.e. is the abbreviation for a two-word Latin term, id est. "
+ + "Translated word for word, id est means\"that is.\"";
+ toParse[10] = "This specification defines the HyperText Markup Language (HTML),"
+ + "version 4.0, the publishing language...";
+ toParse[11] = "Published 2005-08-10";
+ toParse[12] = "Number pi is approximately equal to 3.14.";
+ toParse[13] = "Number pi is approximately equal to 3.14";
+
+ byte[][] CorrectMarksPosition = new byte[toParse.length][];
+ for(int i = 0; i < toParse.length; i++){
+ CorrectMarksPosition[i] = new byte[toParse[i].length()+1];
+ }
+
+ for(int i = 0; i < CorrectMarksPosition.length; i++){
+ for(int j = 0; j < CorrectMarksPosition[i].length; j++)
+ CorrectMarksPosition[i][j] = 0;
+ }
+
+ CorrectMarksPosition[0][0] = 1;
+ CorrectMarksPosition[0][22] = 1;
+
+ CorrectMarksPosition[1][0] = 1;
+ CorrectMarksPosition[1][25] = 1;
+
+ CorrectMarksPosition[2][0] = 1;
+ CorrectMarksPosition[2][27] = 1;
+
+ CorrectMarksPosition[3][0] = 1;
+ CorrectMarksPosition[3][35] = 1;
+
+ CorrectMarksPosition[4][0] = 1;
+ CorrectMarksPosition[4][35] = 1;
+
+ CorrectMarksPosition[5][0] = 1;
+ CorrectMarksPosition[5][37] = 1;
+
+ CorrectMarksPosition[6][0] = 1;
+ CorrectMarksPosition[6][28] = 1;
+ CorrectMarksPosition[6][37] = 1;
+
+ CorrectMarksPosition[7][0] = 1;
+ CorrectMarksPosition[7][71] = 1;
+
+ CorrectMarksPosition[8][0] = 1;
+ CorrectMarksPosition[8][48] = 1;
+
+ CorrectMarksPosition[9][0] = 1;
+ CorrectMarksPosition[9][60] = 1;
+ CorrectMarksPosition[9][108] = 1;
+
+ CorrectMarksPosition[10][0] = 1;
+ CorrectMarksPosition[10][103] = 1;
+
+ CorrectMarksPosition[11][0] = 1;
+ CorrectMarksPosition[11][20] = 1;
+
+ CorrectMarksPosition[12][0] = 1;
+ CorrectMarksPosition[12][41] = 1;
+
+ CorrectMarksPosition[13][0] = 1;
+ CorrectMarksPosition[13][40] = 1;
+
+ for (int i = 0; i < toParse.length; i++) {
+
+ SIterator_Marker_Ch SI = new SIterator_Marker_Ch(toParse[i]);
+
+ Thread.yield();
+
+ int boundary = SI.sentenceIterator.first();
+ SI.markArr[boundary] = 1;
+
+ while (boundary != BreakIterator.DONE) {
+ SI.markers.setCharAt(boundary, '^');
+ boundary = SI.sentenceIterator.next();
+ if (boundary != BreakIterator.DONE){
+ SI.markArr[boundary] = 1;
+ }
+ Thread.yield();
+ } //while
+
+ //base.log.add(" " + SI.ScanStr + "\r\n"
+ // + "-----------------------" + SI.markers);
+ Thread.yield();
+ if(! Arrays.equals(SI.markArr,CorrectMarksPosition[i])){
+ base.statuses[id] = Status.FAIL;
+ base.log.add("Thread "+ id
+ + ":" + SI.ScanStr + "\r\n"
+ + "------------------------------" + SI.markers + "\r\n"
+ + "This sentance break was made incorrect");
+
+ }
+
+ }//for
+
+ if (base.callSystemGC != 0) {
+ System.gc();
+ }
+
+ }//while
+ if(base.statuses[id] != Status.FAIL){
+ base.statuses[id] = Status.PASS;
+ }
+ }
+}
+
+ //class Status {
+ // public static final int FAIL = -10;
+ // public static final int PASS = 10;
+ //}
+
+class SIterator_Marker_Ch {
+ public BreakIterator sentenceIterator;
+
+ public StringBuffer markers;
+
+ public byte[] markArr;
+
+ public String ScanStr;
+
+ public SIterator_Marker_Ch(String toScan) {
+ Locale currentLocale = new Locale("en", "US");
+ sentenceIterator = BreakIterator.getSentenceInstance(currentLocale);
+
+ markers = new StringBuffer();
+
+ sentenceIterator.setText(toScan);
+
+ markers.setLength(toScan.length() + 1);
+ for (int j = 0; j < markers.length(); j++) {
+ markers.setCharAt(j, ' ');
+ }
+ ScanStr = new String(toScan);
+
+ markArr = new byte[ScanStr.length()+1];
+ for (int j = 0; j < markArr.length; j++){
+ markArr[j] = 0;
+ }
+ }
+}
\ No newline at end of file
Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/getSentenceInstance_check.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/util/ConcurrentTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/util/ConcurrentTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/util/ConcurrentTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/util/ConcurrentTest.java Fri Jun 8 09:34:52 2007
@@ -0,0 +1,276 @@
+/*
+ * Copyright 2007 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author Aleksey Ignatenko
+ * @version $Revision: 1.0 $
+ */
+
+/*
+ * Goal: Test java.util.concurrent package
+ * The main idea is to test loading of the same class in many threads
+ * All synchronizations are to be done on classloader level in VM
+ * The main members of the test are: initiating, defining classloaders,
+ * delegation model
+ *
+ * passed parameters:
+ * parameter[0] - number of threads to start
+ *
+ * The test Thread does the following, 2 stages:
+ * 1 stage:
+ * * runs NumberOfThreads interacting w each other:
+ * a. CopyOnWriteArrayList + Exchanger
+ * b. Sending and receiving among threads via PriorityBlockingQueue
+ * c. Semaphore is used for synch purpose of weak place in code
+ * *
+ * 2 stage:
+ * * runs NumberOfThreads by scheduler ScheduledThreadPoolExecutor
+ * * threads do the a,b,c, actions
+ *
+ * */
+
+package org.apache.harmony.test.reliability.api.util;
+
+import java.util.ArrayList;
+import java.util.Random;
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.Exchanger;
+import java.util.concurrent.PriorityBlockingQueue;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.harmony.test.reliability.share.Test;
+
+public class ConcurrentTest extends Test{
+ static volatile boolean failed = false;
+ static final int NUMBER_OF_THREADS = 30;
+ static int numberOfThreads = NUMBER_OF_THREADS;
+ static Semaphore sm = null;
+
+ static CyclicBarrier cb;
+
+ public static void main(String[] params){
+ System.exit(new ConcurrentTest().test(params));
+ }
+
+ public int test(String[] params){
+ parseParams(params);
+ cb = new CyclicBarrier(numberOfThreads);
+ int thirdOfThreads = (int)(numberOfThreads/3);
+ sm = new Semaphore(thirdOfThreads);
+
+ // 1-st run as usual threads
+ Thread[] thrds = new Thread[numberOfThreads];
+ for (int i = 0; i<thrds.length; i++){
+ thrds[i] = new cnRunner();
+ thrds[i].start();
+ }
+
+ for (int i = 0; i<thrds.length; i++){
+ try {
+ thrds[i].join();
+ } catch (InterruptedException e) {
+ return fail("FAILED");
+ }
+ }
+
+ if (failed == true){
+ return fail("FAILED");
+ }
+
+ // 2-nd run - threads are launched with scheduler - short cycle = 100 milliseconds
+ ScheduledThreadPoolExecutor stpe = new ScheduledThreadPoolExecutor(numberOfThreads);
+ ArrayList<Thread> ar = new ArrayList<Thread>();
+ for (int i=0; i<numberOfThreads; i++){
+ Thread rn = new cnRunner();
+ ar.add(rn);
+ stpe.schedule(rn, cnRunner.rm.nextInt(100), TimeUnit.MILLISECONDS);
+ }
+ try {
+ stpe.awaitTermination(100, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ // Expected
+ }
+
+ if (failed == true){
+ return fail("FAILED");
+ }
+
+ return pass("OK");
+ }
+
+ public void parseParams(String[] params) {
+
+ if (params.length >= 1) {
+ numberOfThreads = Integer.parseInt(params[0]);
+ }
+ }
+}
+
+class cnRunner extends Thread{
+ static Random rm = new Random();
+ static AtomicLong stats = new AtomicLong(0);
+ static Exchanger<String> exch = new Exchanger<String>();
+ static CopyOnWriteArrayList<String> tArray = new CopyOnWriteArrayList<String>();
+ static PriorityBlockingQueue<String> bQue = new PriorityBlockingQueue<String>();
+
+ public void run (){
+ // Stage 1: test CopyOnWriteArrayList + Exchanger
+ String currThrdId = new String ("");
+ try {
+ stats.getAndAdd(ConcurrentTest.cb.getNumberWaiting());
+ currThrdId = new Long(Thread.currentThread().getId()).toString();
+ tArray.add(currThrdId);
+ ConcurrentTest.cb.await();
+ } catch (InterruptedException e) {
+ ConcurrentTest.log.add("Failed to wait all starting threads, stage 1!");
+ ConcurrentTest.failed = true;
+ } catch (BrokenBarrierException e) {
+ ConcurrentTest.log.add("Failed to wait all starting threads, stage 1!");
+ ConcurrentTest.failed = true;
+ }
+
+ if (ConcurrentTest.cb.isBroken()){
+ ConcurrentTest.log.add("Failed to wait all starting threads!");
+ ConcurrentTest.failed = true;
+ }
+
+ // The task for thread: try to find its name for 100 exchange operations
+ int counter = rm.nextInt(300)+100;
+ try {
+ Thread.sleep(rm.nextInt(100)+1);
+ } catch (InterruptedException e1) {
+ ConcurrentTest.failed = true;
+ }
+ String thrdId = tArray.remove(0);
+ while (counter > 0){
+ if (thrdId == currThrdId){
+ break;
+ }
+ try {
+ thrdId = exch.exchange(thrdId, rm.nextInt(100)+1, TimeUnit.MILLISECONDS);
+ } catch (InterruptedException e) {
+ ConcurrentTest.failed = true;
+ } catch (TimeoutException e) {
+ // Expected
+ }
+ counter--;
+ }
+ //System.out.println(counter);
+
+ try {
+ stats.getAndAdd(ConcurrentTest.cb.getNumberWaiting());
+ ConcurrentTest.cb.await();
+ } catch (InterruptedException e) {
+ ConcurrentTest.log.add("Failed to wait all starting threads, stage 1!");
+ ConcurrentTest.failed = true;
+ } catch (BrokenBarrierException e) {
+ ConcurrentTest.log.add("Failed to wait all starting threads, stage 1!");
+ ConcurrentTest.failed = true;
+ }
+
+ // Stage 2: test PriorityBlockingQueue
+ //devide threads to sending and receiving
+ // to thread: Who are you - sender or receiver?
+ counter = rm.nextInt(100);
+ int threadChoice = rm.nextInt(2);
+ if (threadChoice == 0){
+ while (counter > 0){
+ //emit into queue
+ String toQue = "Que_" + new Long(Thread.currentThread().getId()).toString() + "_" + rm.nextInt(100);
+ if (counter == 50){
+ // process one exception
+ toQue = null;
+ }
+ try{
+ bQue.put(toQue);
+ }catch(NullPointerException e){
+ // Expected
+ }
+ counter--;
+ //System.out.println("Emmited " + counter);
+ }
+ } else{
+ while (counter > 0){
+ //read from queue
+ try {
+ bQue.poll(rm.nextInt(100)+1, TimeUnit.MILLISECONDS);
+ } catch (InterruptedException e) {
+ ConcurrentTest.failed = true;
+ }
+ counter--;
+ //System.out.println("Read " + counter);
+ }
+ }
+
+ try {
+ stats.getAndAdd(ConcurrentTest.cb.getNumberWaiting());
+ ConcurrentTest.cb.await();
+ } catch (InterruptedException e) {
+ ConcurrentTest.log.add("Failed to wait all starting threads, stage 2!");
+ ConcurrentTest.failed = true;
+ } catch (BrokenBarrierException e) {
+ ConcurrentTest.log.add("Failed to wait all starting threads, stage 2!");
+ ConcurrentTest.failed = true;
+ }
+
+ // Stage 3: test Semaphore
+ // limit Semathor with 1/3 of number of threads
+ // replaced doing something with rundomized time thread sleep
+ // sm is located in ConcurrentTest bacause we need to initialize it
+ // with 1/3 number of threads
+ counter = 1000;
+ while (counter > 0){
+ try {
+ stats.getAndAdd(ConcurrentTest.sm.availablePermits());
+ ConcurrentTest.sm.acquire();
+ //System.out.println("in");
+ } catch (InterruptedException e) {
+ ConcurrentTest.log.add("Some thread is interrupted, stage 3!");
+ ConcurrentTest.failed = true;
+ }
+
+ try {
+ Thread.currentThread().sleep(rm.nextInt(5)+1);
+ } catch (InterruptedException e) {
+ ConcurrentTest.log.add("Some thread is interrupted, stage 3!");
+ //ConcurrentTest.failed = true;
+ }
+
+ stats.getAndAdd(ConcurrentTest.sm.getQueueLength());
+ ConcurrentTest.sm.release();
+ //System.out.println("out");
+ counter--;
+ }
+
+ // final actions
+ if (ConcurrentTest.cb.isBroken()){
+ ConcurrentTest.log.add("Failed to wait all starting threads, final!");
+ ConcurrentTest.failed = true;
+ }
+
+ ConcurrentTest.cb.reset();
+ }
+
+
+}
+
Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/util/ConcurrentTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/AdlerCRC32Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/AdlerCRC32Test.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/AdlerCRC32Test.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/AdlerCRC32Test.java Fri Jun 8 09:34:52 2007
@@ -0,0 +1,187 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author Oleg Oleinik
+ * @version $Revision: 1.1 $
+ */
+
+package org.apache.harmony.test.reliability.api.zip;
+
+import org.apache.harmony.test.reliability.share.Test;
+
+import java.util.zip.Adler32;
+import java.util.zip.CRC32;
+import java.util.zip.Checksum;
+import java.util.Random;
+
+
+/**
+ * The test does:
+ * 1. Reads parameters, which are:
+ * param[0] - number of Adler32/CRC32.update() iterations
+ * param[1] - byte arrays size to update Adler32 with
+ *
+ * 2. Creates two byte arrays - one with ordered sequential valies, another
+ * with random byte values.
+ *
+ * 3. Starts param[0] iterations. At each iteration:
+ *
+ * a. Creates Adler32 and CRC32 objects.
+ * b. For each object and byte array:
+ * c. in a cycle calls update(byte[] array, 0, length) with variable
+ * length value - from 'array.length' to '0'.
+ * d. checks that getValue() returns the same result being called twice sequentially.
+ * e. calls update(int).
+ * f. calls reset().
+ *
+ * g. calls System.gc();
+ *
+ */
+
+public class AdlerCRC32Test extends Test {
+
+ // Number of iterations
+ public int NUMBER_OF_ITERATIONS = 10;
+
+ // size of allocated byte arrays
+ public int SIZE = 1000;
+
+ public int callSystemGC = 1;
+
+
+ public static void main(String[] args) {
+ System.exit(new AdlerCRC32Test().test(args));
+ }
+
+
+ public int test(String[] params) {
+
+ parseParams(params);
+
+ byte[][] b = new byte[2][];
+
+ // initialize ordered byte array (containing positive and negative values) once
+ b[0] = ByteCreator.getOderedBytes(SIZE);
+
+ long checksum;
+
+ for (int k = 0; k < NUMBER_OF_ITERATIONS; ++k){
+
+ // log.add("Strating " + k + " iteration");
+
+ // initialize random byte array at each iteration
+ b[1] = ByteCreator.getRandomBytes(SIZE);
+
+ Checksum[] cs = {new Adler32(), new CRC32()};
+
+ for (int c = 0; c < cs.length; ++c) { // for each of Checksum algorithms...
+
+ // log.add("" + cs[c].getClass().getName());
+
+ for (int i = 0; i < b.length; ++i){ // for each of byte arrays...
+
+ // log.add("Byte array: " + i);
+
+ for (int j = 0; j <= b[i].length; j += 10){ // for each 'length'...
+
+ // just in case - GC does not free memory allocated for new Adler32, CRC32
+ Adler32 a = new Adler32();
+ CRC32 crc = new CRC32();
+
+ cs[c].update(b[i], 0, b[i].length - j);
+
+ checksum = cs[c].getValue();
+
+ // twice invoked getValue() must return the same result
+ if (cs[c].getValue() != checksum){
+
+ return fail("Checksum: " + cs[c].getClass().getName() + "byte array: " + i +
+ ", iteration in byte array = " + j + ": getValue() != getValue()");
+ }
+
+ // just in case, call update(int) as well
+ cs[c].update(j);
+ }
+
+ cs[c].reset();
+ }
+
+ }
+
+ if (callSystemGC != 0){
+ System.gc();
+ }
+
+ }
+
+ return pass("OK");
+ }
+
+
+ public void parseParams(String[] params) {
+
+ if (params.length >= 1) {
+ NUMBER_OF_ITERATIONS = Integer.parseInt(params[0]);
+ }
+
+ if (params.length >= 2) {
+ SIZE = Integer.parseInt(params[1]);
+ }
+
+ }
+
+}
+
+class ByteCreator {
+
+ public static byte[] getOderedBytes(int size) {
+
+ byte[] b = new byte[size];
+
+ int j = 0;
+
+ // while() provides byte array is filled in with series of sequentially
+ // increased byte values: MIN_VALUE..MAX_VALUE, MIN_VALUE..MAX_VALUE, etc.
+
+ while (j < b.length){
+
+ for (int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE && j < b.length; ++i){
+ b[j++] = (byte) i;
+ }
+
+ }
+
+ return b;
+ }
+
+
+ public static byte[] getRandomBytes(int size) {
+
+ byte[] b = new byte[size];
+
+ Random rand = new Random(10);
+
+ for (int i = 0; i < b.length; ++i) {
+ b[i] = (byte) rand.nextInt(Byte.MAX_VALUE);
+ }
+
+ return b;
+ }
+
+}
+
Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/AdlerCRC32Test.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/GZipInOutStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/GZipInOutStreamTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/GZipInOutStreamTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/GZipInOutStreamTest.java Fri Jun 8 09:34:52 2007
@@ -0,0 +1,248 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author Oleg Oleinik
+ * @version $Revision: 1.2 $
+ */
+
+package org.apache.harmony.test.reliability.api.zip;
+
+import org.apache.harmony.test.reliability.share.Test;
+
+import java.util.zip.GZIPOutputStream;
+import java.util.zip.GZIPInputStream;
+import java.io.FileOutputStream;
+import java.io.FileInputStream;
+import java.io.OutputStream;
+import java.io.InputStream;
+import java.io.File;
+import java.util.Random;
+
+
+/**
+ * Goal: find resource leaks or intermittent failures caused by writing into
+ * single FileOutputStream by multiple GZIPOutputStreams successively (without close-ing).
+ *
+ * The test does:
+ *
+ * 1. Reads parameters, which are:
+ * 1) args[0] - number of GZIPOutputStreams to write successively into one FileOutputStream
+ * 2) args[1] - output directory where to write output file. Must exist prior to test invocation.
+ *
+ * 2. Creates FileOutputWriter into output file whose full name is "args[1]/GZipInOutStreamTest.out.gz",
+ * before creation checks the file for existance and if such file already exists, removes it.
+ *
+ * 3. In a cycle for args[0] iterations:
+ *
+ * 1) Creates GZIPOutputStream over a single FileOutputWriter
+ * 2) Writes an array of random bytes into it
+ * 3) Calls finish(), but not close.
+ *
+ * 4. Calls GZIPOutputStream.close().
+ *
+ * 5. Reads from the file via GZIPInputStream.
+ *
+ */
+
+public class GZipInOutStreamTest extends Test {
+
+ static Random r = new Random(10);
+
+ String fileName = "";
+
+ String outputFileName = "GZipInOutStreamTest.out.gz";
+
+ int NUM_ITERATIONS = 10;
+
+ int Multiplier = 1000;
+
+ String outputDir = "";
+
+ static final int BUF_SIZE = 10000;
+
+ public static void main(String[] args) {
+ System.exit(new GZipInOutStreamTest().test(args));
+ }
+
+ public int test(String[] params) {
+
+ parseParams(params);
+
+ FileOutputStream fos = null;
+ FileInputStream fis = null;
+
+ try {
+ createTmpDir(outputDir);
+ } catch (Exception t){
+ log.add(t.toString());
+ return fail("Creates tmp directory: Failed");
+
+ }
+
+ fileName = outputDir + File.separator + outputFileName;
+
+ try {
+
+ // write into GZIPOutputStream/FileOutputStream
+
+ fos = new FileOutputStream(outputFile(fileName));
+ createGZipFile(fos);
+
+ // read from GZIPInputStream/FileInputStream
+
+ fis = new FileInputStream(inputFile(fileName));
+ readGZipFile(fis);
+
+ } catch (Throwable t){
+
+ log.add(t.toString());
+ t.printStackTrace();
+ return fail("Failed");
+
+ } finally {
+
+ try {
+ if (fos != null){
+ fos.close();
+ }
+ if (fis != null){
+ fis.close();
+ }
+ } catch (Throwable t){
+ }
+ }
+
+ return pass("OK");
+ }
+
+
+ public void parseParams(String[] params) {
+
+ if (params.length >= 1) {
+ NUM_ITERATIONS = Integer.parseInt(params[0]);
+ }
+
+ // NOTE: outputDir must exist prior to running this test
+
+ if (params.length >= 2) {
+ outputDir = params[1];
+ }
+
+ fileName = outputDir + File.separator + outputFileName;
+
+ }
+
+ public File outputFile(String name) throws Exception {
+
+ File f = new File(name);
+
+ if (f.exists()){
+ f.delete();
+ }
+
+ return f;
+ }
+
+
+ public File inputFile(String fileName) throws Exception {
+
+ File f = new File(fileName);
+
+ if (!f.exists()) {
+ throw new Exception("Unexpected: file " + f.getName() + " does not exist...");
+ }
+
+ return f;
+ }
+
+
+ public void readGZipFile(InputStream is) throws Exception {
+
+ // read from the InputStream, BUF_SIZE and read bytes
+ // actualy do not mean anything
+
+ GZIPInputStream gzis = new GZIPInputStream(is, BUF_SIZE);
+
+ byte[] bb = new byte[BUF_SIZE + 100];
+
+ while (gzis.available() != 0) {
+ gzis.read(bb, 0, bb.length);
+ }
+
+ gzis.close();
+ }
+
+
+ public void createGZipFile(OutputStream os) throws Exception {
+
+ GZIPOutputStream gzos = null;
+
+ for (int i = 1; i < NUM_ITERATIONS; ++i){
+
+ gzos = new GZIPOutputStream(os, getNextSize(i));
+
+ // get random byte array of getNextSize(i) length
+
+ byte[] b = GetBytes(getNextSize(i));
+
+ // log.add("Iteration " + i + ", writing " + b.length + " bytes");
+
+ gzos.write(b, 1, b.length - 1);
+
+ // finish, but, not close - for the next GZIPOutputStream to
+ // write into the same FileOutputStream
+
+ gzos.finish();
+ }
+
+ if (gzos != null) {
+ gzos.close();
+ }
+ }
+
+ public void createTmpDir(String outputDir) throws Exception {
+ File temp = new File(outputDir);
+
+ if(temp.exists()) {
+ File[] lstf = temp.listFiles();
+ for( int i = 0; i < lstf.length; i++) {
+ if( !lstf[i].delete()) {
+ log.add("Delete " + lstf[i].getName() + " file: Failed.");
+ }
+ }
+ }
+ temp.mkdir();
+ }
+
+
+ int getNextSize(int i){
+ return i * Multiplier;
+ }
+
+ byte[] GetBytes(int size){
+
+ byte[] b = new byte[size];
+
+ for (int i = 0; i < b.length; ++i){
+ b[i] = (byte) r.nextInt(Byte.MAX_VALUE);
+ }
+ return b;
+ }
+
+}
+
Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/GZipInOutStreamTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/InflDeflGetResetTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/InflDeflGetResetTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/InflDeflGetResetTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/InflDeflGetResetTest.java Fri Jun 8 09:34:52 2007
@@ -0,0 +1,287 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author Oleg Oleinik
+ * @version $Revision: 1.1 $
+ */
+
+package org.apache.harmony.test.reliability.api.zip;
+
+import org.apache.harmony.test.reliability.share.Test;
+
+import java.util.zip.DataFormatException;
+import java.util.zip.Deflater;
+import java.util.zip.Inflater;
+import java.util.Random;
+
+/**
+ * Goal: cover getTotalIn(), getTotalOut(), reset(), end() methods and reveal
+ * possible resource leaks when working with a single instance of Deflater/Inflater.
+ *
+ * The test does:
+ * 1. Reads parameters, which are:
+ * param[0] - number of internal iterations
+ * param[1] - maximum byte array size to deflate/inflate
+ *
+ * 2. On each iteration:
+ *
+ * 3. Creates NUM_BYTE_ARRAYS arrays of variable random length and random byte values.
+ * Creates single instance of Deflater and Inflater. Then, for each array:
+ *
+ * 4. Deflates it into a byte array of sufficient length, checks for correctness values
+ * returned by getTotalIn(), getTotalOut(), remembers adler checksum and resets Deflater.
+ *
+ * 5. Does one additional step - deflates a byte array into small output array, does not
+ * reset Deflater, instead, just closes the Deflater (hoping this will cause a leak).
+ *
+ * 6. Inflates each of deflated arrays into a byte array of sufficient length, checks for
+ * correctness values returned by getTotalIn(), getTotalOut() and adler checksum, resets Inflater.
+ *
+ * 7. Does one additional step - inflates a byte array into small output array, does not
+ * reset Inflater, instead, just closes the Inflater (hoping this will cause a leak).
+ *
+ * 8. Calls System.gc();
+ *
+ */
+
+public class InflDeflGetResetTest extends Test {
+
+ // In-memory buffer size
+ public int bufferSize = 1024;
+
+ public static final int NUM_BYTE_ARRAYS = 10;
+
+ public int NumberOfIterations = 100;
+
+ public int callSystemGC = 1;
+
+
+ public static void main(String[] args) {
+ System.exit(new InflDeflGetResetTest().test(args));
+ }
+
+
+ public int test(String[] params) {
+
+ parseParams(params);
+
+ for (int j = 0; j < NumberOfIterations; ++j) {
+
+ // array of NUM_BYTE_ARRAYS byte arrays to be filled in and compressed
+ byte[][] b_to_compress = new byte[NUM_BYTE_ARRAYS][];
+
+ // array of NUM_BYTE_ARRAYS byte arrays into which we will compress
+ byte[][] b_compressed = new byte[NUM_BYTE_ARRAYS][];
+
+ // array of NUM_BYTE_ARRAYS byte arrays into which we will decompress
+ byte[][] b_decompress_to = new byte[NUM_BYTE_ARRAYS][];
+
+ // number of bytes deflate() returned for each of NUM_BYTE_ARRAYS byte arrays
+ int[] compressed_sizes = new int[NUM_BYTE_ARRAYS];
+
+ // adler checksums for each of compressed NUM_BYTE_ARRAYS byte arrays
+ int[] adler_before = new int[NUM_BYTE_ARRAYS];
+
+ // use a single instance of Deflater for operations with NUM_BYTE_ARRAYS arrays
+
+ Deflater defl = new Deflater();
+
+ for (int i = 0; i < b_to_compress.length; ++i){
+
+ // create byte array of random width with random byte values
+
+ b_to_compress[i] = ByteArray.getRandomBytes(bufferSize);
+
+ // create array of sufficient size into which we will store compressed bytes
+
+ b_compressed[i] = new byte[b_to_compress[i].length * 2];
+
+ defl.setInput(b_to_compress[i]);
+ defl.finish();
+
+ // store number of bytes returned by deflate()
+
+ compressed_sizes[i] = defl.deflate(b_compressed[i]);
+
+ if (defl.getTotalOut() != compressed_sizes[i]) {
+ log.add("Iteration: " + j + ", getTotalOut() returns " + defl.getTotalOut()
+ + ", while deflate() returned " + compressed_sizes[i]);
+ }
+
+ if (defl.getTotalIn() != b_to_compress[i].length) {
+ log.add("Iteration: " + j + ", getTotalIn() returns " + defl.getTotalIn() +
+ ", while to be compressed array size is " + b_to_compress[i].length);
+ }
+
+ // store adler checksum
+
+ adler_before[i] = defl.getAdler();
+
+ defl.reset();
+
+ }
+
+ // final operation - compress the 10-th part of some array, for example
+ // lets take b_to_compress[0]:
+
+ defl.setInput(b_to_compress[0], 0, b_to_compress[0].length / 10);
+ defl.finish();
+
+ // compress this 10-th part into 10-th part of another newly created array
+ // why? - just in case deflate looses memory is byte array into which we compress
+ // is smaller than required for complete compression and we end() our deflater.
+
+ int c_s = defl.deflate(new byte[compressed_sizes[0] / 10]);
+
+ // intentionally commented reset() - to try to loose left unused part of array
+ // b_compressed[0] or the whole array.
+
+ // defl.reset();
+
+ defl.end();
+
+ // use a single instance of Inflater for operations with NUM_BYTE_ARRAYS arrays
+
+ Inflater infl = new Inflater();
+
+ for (int i = 0; i < b_to_compress.length; ++i){
+
+ b_decompress_to[i] = new byte[b_to_compress[i].length * 2];
+
+ infl.setInput(b_compressed[i], 0, compressed_sizes[i]);
+
+ int inflated_bytes = 0;
+
+ try {
+
+ inflated_bytes = infl.inflate(b_decompress_to[i]);
+
+ } catch (DataFormatException dfe){
+ log.add("Iteration: " + j + " DataFormatException is thrown");
+ continue;
+ }
+
+ if (adler_before[i] != infl.getAdler()) {
+ log.add("adler before compression is: " + adler_before[i] + ", adler after is: "
+ + infl.getAdler());
+ }
+
+ if (inflated_bytes != b_to_compress[i].length){
+ log.add("inflate() returned " + inflated_bytes + " instead of " + b_to_compress[i].length);
+ }
+
+ if (infl.getTotalOut() != inflated_bytes) {
+ log.add("getTotalOut() returns " + infl.getTotalOut() + ", while inflate() returned "
+ + inflated_bytes);
+ }
+
+ if (infl.getTotalIn() != compressed_sizes[i]) {
+ log.add("getTotalIn() returns " + infl.getTotalIn() + ", while to be decompressed " +
+ " byte numebr is " + compressed_sizes[i]);
+ }
+
+ infl.reset();
+
+ // log.add(" " + j + " " + i + " " + b_to_compress[i].length + " " +
+ // compressed_sizes[i] + " " + inflated_bytes);
+ }
+
+ // lets try to check whether inflate() looses memory if we inflate into
+ // array of insufficient size and just forget about this array, end()-ing
+ // the inflater:
+
+ infl.setInput(b_compressed[0], 0, compressed_sizes[0]);
+
+ try {
+
+ infl.inflate(b_decompress_to[0], 0, b_decompress_to[0].length / 10);
+
+ } catch (DataFormatException dfe){
+ log.add("Last compression: Iteration: " + j + " DataFormatException is thrown");
+ }
+
+ // intentionally commented reset() - to try to loose left unused part of array
+ // b_decompress_to[0] or the whole array.
+
+ // infl.reset();
+
+ infl.end();
+
+
+ if (callSystemGC != 0){
+ System.gc();
+ }
+ }
+
+ return pass("OK");
+ }
+
+
+ public void parseParams(String[] params) {
+
+ if (params.length >= 1) {
+ NumberOfIterations = Integer.parseInt(params[0]);
+ //log.add("Number of iterations : " + NumberOfIterations);
+ }
+
+ if (params.length >= 2) {
+ bufferSize = Integer.parseInt(params[1]);
+ }
+
+ }
+
+}
+
+
+class ByteArray {
+
+ static Random rand = new Random();
+
+ public static byte[] getRandomBytes(int size) {
+
+ byte[] b = new byte[100 + rand.nextInt(size)];
+
+ for (int i = 0; i < b.length; ++i) {
+ b[i] = (byte) rand.nextInt(Byte.MAX_VALUE);
+ }
+
+ return b;
+
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/InflDeflGetResetTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/ZipEntryIterateThreadingTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/ZipEntryIterateThreadingTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/ZipEntryIterateThreadingTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/ZipEntryIterateThreadingTest.java Fri Jun 8 09:34:52 2007
@@ -0,0 +1,221 @@
+/*
+ * Copyright 2007 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author Aleksey Ignatenko
+ * @version $Revision: 1.0 $
+ */
+
+package org.apache.harmony.test.reliability.api.zip;
+
+import org.apache.harmony.test.reliability.share.Test;
+
+import java.io.File;
+import java.util.Enumeration;
+import java.util.ArrayList;
+import java.util.zip.ZipFile;
+import java.util.zip.ZipEntry;
+
+
+/**
+ * Goal: check that runtime works correctly when multiple threads are reading
+ * and receiving all entries of all/each jar file from java.home directory
+ * and subdirectories.
+ * Also, check that GC closes ZipFiles resources when they are not needed
+ * and objects used them can be collected.
+ *
+ * The test does:
+ *
+ * 1. Reads parameters, which are:
+ * param[0] - number of threads which receive entries of all/each jar
+ * file in parallel.
+ *
+ * 2. Finds all jar files in java.home and its subdirectories.
+ *
+ * 3. Creates param[0] threads and starts them:
+ *
+ * Each running thread:
+ * - for each found jar file receives all its entries via
+ * new ZipFile(<jar filename>).entries();
+ *
+ * - closes every second created ZipFile.
+ *
+ * 5. Joins all threads
+ *
+ */
+
+
+public class ZipEntryIterateThreadingTest extends Test{
+
+ static final String JAR_FILE_EXTENSION = ".jar";
+
+ static int NUMBER_OF_THREADS = 600;
+
+ ArrayList<String> jarFiles; // contains names of found jar files
+
+ volatile boolean failed; // flag signals whether there was an error during test execution
+
+
+ public static void main(String[] args) {
+ System.exit(new ZipEntryIterateThreadingTest().test(args));
+ }
+
+
+ public int test(String[] params) {
+
+ cleanUp();
+
+ // System.out.println("ZipEntryIterateThreaddingTest started...");
+
+ parseParams(params);
+
+ // System.out.println("Number of threads to start " + NUMBER_OF_THREADS);
+
+ String rootDir = getDirToScanForJarFiles();
+
+ scanDirForJarFiles(rootDir);
+
+ /* needed for test debugging only:
+
+ System.out.println("Jar files found in " + rootDir + ":");
+
+ for (int i = 0; i < jarFiles.size(); i++){
+ System.out.println(jarFiles.get(i));
+ }
+
+ */
+
+ Thread thrds[] = new Thread[NUMBER_OF_THREADS];
+
+ // System.out.println("Starting threads");
+
+ for (int i = 0; i < thrds.length; i++) {
+ thrds[i] = new Zipper(this);
+ thrds[i].start();
+ }
+
+ // System.out.println("\n Joining threads...");
+
+ for (int j = 0; j < thrds.length; j++) {
+
+ try {
+
+ thrds[j].join();
+ // System.out.print(".");
+
+ } catch (InterruptedException e) {
+ log.add("" + e.getMessage() + " exception while joining " + j + "-th thread");
+ failed = true;
+ }
+
+ }
+
+ if (failed) {
+ return fail("");
+ }
+
+ return pass("OK");
+ }
+
+ void cleanUp() {
+ jarFiles = new ArrayList<String>();
+ failed = false;
+ }
+
+ public void parseParams(String[] params) {
+
+ if (params.length >= 1) {
+ NUMBER_OF_THREADS = Integer.parseInt(params[0]);
+ }
+ }
+
+
+ String getDirToScanForJarFiles() {
+ return System.getProperty("java.home");
+ }
+
+
+ void scanDirForJarFiles(String rootDir) {
+
+ try {
+
+ File fl = new File (rootDir);
+ File[] files = fl.listFiles();
+
+ for (int i = 0; i < files.length; i++) {
+
+ if (files[i].isDirectory()){
+ scanDirForJarFiles(files[i].getAbsolutePath());
+ continue;
+ }
+
+ if (files[i].getName().endsWith(JAR_FILE_EXTENSION)){
+ jarFiles.add(files[i].getAbsolutePath());
+ }
+ }
+
+ // cleanup
+ files = null;
+ fl = null;
+
+ } catch(Exception ex) {
+ log.add("Failed to scan directory for jar files, thrown exception: " + ex.getMessage());
+ failed = true;
+ }
+ }
+
+}
+
+
+
+class Zipper extends Thread {
+
+ ZipEntryIterateThreadingTest base;
+
+ public Zipper(ZipEntryIterateThreadingTest base) {
+ this.base = base;
+ }
+
+ public void run() {
+
+ try {
+
+ // System.out.print(".");
+
+ for (int i = 0; i < base.jarFiles.size(); i++){
+
+ ZipFile xf = new ZipFile(base.jarFiles.get(i));
+
+ Enumeration en = xf.entries();
+
+ while(en.hasMoreElements()){
+ ZipEntry ze = (ZipEntry) en.nextElement();
+ }
+
+ if (i % 2 == 0) {
+ xf.close();
+ xf = null;
+ } else {
+ xf = null;
+ }
+ }
+ } catch (Exception e) {
+ base.log.add(this.getName() + " thrown exception: " + e.getMessage());
+ base.failed = true;
+ }
+ }
+}
Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/ZipEntryIterateThreadingTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/ZipInOutStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/ZipInOutStreamTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/ZipInOutStreamTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/ZipInOutStreamTest.java Fri Jun 8 09:34:52 2007
@@ -0,0 +1,271 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author Nikolay V. Bannikov
+ * @version $Revision: 1.1 $
+ */
+
+package org.apache.harmony.test.reliability.api.zip;
+
+import org.apache.harmony.test.reliability.share.Test;
+
+import java.util.zip.ZipOutputStream;
+import java.util.zip.ZipInputStream;
+import java.util.zip.Deflater;
+import java.io.FileOutputStream;
+import java.io.FileInputStream;
+import java.io.OutputStream;
+import java.io.InputStream;
+import java.io.File;
+import java.util.zip.ZipEntry;
+import java.util.Random;
+
+
+/**
+ * Goal: find memory leaks caused by using hyarchive library method.
+ *
+ * The test does:
+ * 1. Reads parameters, which are:
+ * param[0] - number of nesting zip entry
+ * param[1] - path to Zip file's directory
+ * 2. Creates a zip file with different zip strategy and nesting of zip entry.
+ * 3. Writes the random bytes into the entries.
+ * 4. Check writing bytes
+ */
+
+public class ZipInOutStreamTest extends Test {
+
+ static Random r = new Random(10);
+
+ String fileName = "";
+
+ String outputFileName = "ZipInOutStreamTest.out.zip";
+
+ int NUM_ENTRIES = 10;
+
+ int Multiplier = 1000;
+
+ String outputDir = "";
+
+ public int[] strategies = new int [] {
+ Deflater.DEFAULT_STRATEGY,
+ Deflater.HUFFMAN_ONLY,
+ Deflater.FILTERED
+ };
+
+ public int[] level = new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
+
+ int LEVEL = 0;
+ int STRATEGY = Deflater.DEFAULT_STRATEGY;
+
+ public static void main(String[] args) {
+ System.exit(new ZipInOutStreamTest().test(args));
+ }
+
+
+ public int test(String[] params) {
+
+ parseParams(params);
+
+ try {
+ createTmpDir(outputDir);
+ } catch (Exception t){
+ log.add(t.toString());
+ return fail("Creates tmp directory: Failed");
+
+ }
+
+ fileName = outputDir + File.separator + outputFileName;
+
+ FileOutputStream fos = null;
+ FileInputStream fis = null;
+
+ for (int x = 0; x < level.length; ++x) {
+
+ for (int y = 0; y < strategies.length; ++y) {
+
+ LEVEL = level[x];
+ STRATEGY = strategies[y];
+
+ try {
+
+ fos = new FileOutputStream(outputFile(fileName));
+ createZipFile(fos);
+
+ fis = new FileInputStream(inputFile(fileName));
+ readZipFile(fis);
+
+ } catch (Throwable t){
+
+ log.add(t.toString());
+ return fail("Failed");
+
+ } finally {
+ try {
+ if (fos != null){
+ fos.close();
+ }
+ if (fis != null){
+ fis.close();
+ }
+ } catch (Throwable t){
+ }
+ }
+
+ } // for strategies
+
+ } // for level
+
+ return pass("OK");
+ }
+
+
+ public void parseParams(String[] params) {
+
+ if (params.length >= 1) {
+ NUM_ENTRIES = Integer.parseInt(params[0]);
+ }
+
+ // NOTE: outputDir must exist prior to running this test
+
+ if (params.length >= 2) {
+ outputDir = params[1];
+ }
+
+
+ }
+
+ public File outputFile(String name) throws Exception {
+
+ File f = new File(name);
+
+ if (f.exists()){
+ f.delete();
+ }
+
+ return f;
+ }
+
+
+ public File inputFile(String fileName) throws Exception {
+
+ File f = new File(fileName);
+
+ if (!f.exists()) {
+ throw new Exception("Unexpected: file " + f.getName() + " does not exist...");
+ }
+
+ return f;
+ }
+
+
+ public void readZipFile(InputStream is) throws Exception {
+
+ ZipInputStream zis = new ZipInputStream(is);
+
+ int i = 0;
+ ZipEntry z;
+ byte[] bb = new byte[100];
+
+ while ((z = zis.getNextEntry()) != null) {
+
+ int read_bytes = 0;
+ int r = 0;
+
+ while ((r = zis.read(bb)) != -1){
+ read_bytes += r;
+ }
+
+ if (read_bytes != getNextSize(i)) {
+ throw new Exception("Unexpected: zip entry " + z.getName() + " read " + read_bytes + " instead of " + getNextSize(i));
+ }
+
+ // log.add(z.getName() + " read " + read_bytes + ", expected " + getNextSize(i));
+
+ ++i;
+
+ zis.closeEntry();
+ }
+
+ if (i != NUM_ENTRIES) {
+ throw new Exception("Unexpected: " + i + " zip entries were read instead of " + NUM_ENTRIES);
+ }
+
+ zis.close();
+
+ }
+
+ public void createZipFile(OutputStream os) throws Exception {
+
+ ZipOutputStream zos = new ZipOutputStream(os);
+
+ zos.setComment("This is comment");
+
+ for (int i = 0; i < NUM_ENTRIES; ++i){
+
+ String s = "";
+
+ for (int j = 0; j < i; ++j) {
+ s += j + File.separator;
+ }
+
+ s += i + ".txt";
+
+ zos.putNextEntry(new ZipEntry(s));
+
+ byte[] b = GetBytes(getNextSize(i));
+
+ zos.write(b);
+ }
+
+ zos.closeEntry();
+ zos.close();
+
+ }
+
+ public void createTmpDir(String outputDir) throws Exception {
+ File temp = new File(outputDir);
+
+ if(temp.exists()) {
+ File[] lstf = temp.listFiles();
+ for( int i = 0; i < lstf.length; i++) {
+ if( !lstf[i].delete()) {
+ log.add("Delete " + lstf[i].getName() + " file: Failed.");
+ }
+ }
+ }
+ temp.mkdir();
+ }
+
+
+ int getNextSize(int i){
+ return i * Multiplier;
+ }
+
+ byte[] GetBytes(int size){
+
+ byte[] b = new byte[size];
+
+ for (int i = 0; i < b.length; ++i){
+ b[i] = (byte) r.nextInt(Byte.MAX_VALUE);
+ }
+ return b;
+ }
+
+}
+
Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/ZipInOutStreamTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/ZlibDeflaterTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/ZlibDeflaterTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/ZlibDeflaterTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/ZlibDeflaterTest.java Fri Jun 8 09:34:52 2007
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author Nikolay Bannikov
+ * @version $Revision: 1.1 $
+ */
+
+package org.apache.harmony.test.reliability.api.zip;
+
+import org.apache.harmony.test.reliability.share.Test;
+import java.util.zip.Deflater;
+
+/**
+ * Goal: find memory leaks caused by compressor with the default compression level.
+ *
+ * The test does:
+ * 1. Reads parameters, which are:
+ * param[0] - number of iterations to call/initialize a new compressor in a cycle
+ * 2. starts a cycle of param[0] iterations. On each iteration:
+ * - Creates a new compressor with the default compression level
+ * - runs System.gc()
+ *
+ */
+
+public class ZlibDeflaterTest extends Test {
+
+ public int callSystemGC = 1;
+
+ public int NUMBER_OF_ITERATIONS = 5000;
+
+ public static void main(String[] args) {
+ System.exit(new ZlibDeflaterTest().test(args));
+ }
+
+ public int test(String[] params) {
+
+ parseParams(params);
+
+ for (int i = 0; i < NUMBER_OF_ITERATIONS; ++i) {
+
+ //if (i % 1000 == 0) {
+ // log.add("Iteration: " + i);
+ //}
+
+ new Deflater();
+
+ try {
+ Thread.sleep(10);
+ } catch (Exception e) {
+ }
+
+ if (callSystemGC != 0) {
+ System.gc();
+ }
+ }
+ return pass("OK");
+ }
+
+ public void parseParams(String[] params) {
+
+ if (params.length >= 1) {
+ NUMBER_OF_ITERATIONS = Integer.parseInt(params[0]);
+ }
+
+ }
+
+
+}
+
Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/ZlibDeflaterTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/ZlibDefsetDictionaryTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/ZlibDefsetDictionaryTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/ZlibDefsetDictionaryTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/ZlibDefsetDictionaryTest.java Fri Jun 8 09:34:52 2007
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author Nikolay Bannikov
+ * @version $Revision: 1.1 $
+ */
+
+package org.apache.harmony.test.reliability.api.zip;
+
+import org.apache.harmony.test.reliability.share.Test;
+import java.util.zip.Deflater;
+
+/**
+ * Goal: find memory leaks caused by a preset dictionary for compression.
+ *
+ * The test does:
+ * 1. Reads parameters, which are:
+ * param[0] - number of iterations to call/initialize a preset dictionary for compression in a cycle
+ * 2. starts a cycle of param[0] iterations. On each iteration:
+ * - sets preset dictionary for compression
+ * - runs System.gc()
+ *
+ */
+
+public class ZlibDefsetDictionaryTest extends Test {
+
+ public int callSystemGC = 1;
+
+ public int NUMBER_OF_ITERATIONS = 10000000;
+
+ public static void main(String[] args) {
+ System.exit(new ZlibDefsetDictionaryTest().test(args));
+ }
+
+ public int test(String[] params) {
+
+ parseParams(params);
+
+ Deflater def = new Deflater();
+
+ for (int i = 0; i < NUMBER_OF_ITERATIONS; ++i) {
+
+ //if (i % 1000000 == 0) {
+ // log.add("Iteration: " + i);
+ //}
+
+ def.setDictionary(new byte[1], 0, 1);
+
+ if (callSystemGC != 0) {
+ System.gc();
+ }
+ }
+ return pass("OK");
+ }
+
+ public void parseParams(String[] params) {
+
+ if (params.length >= 1) {
+ NUMBER_OF_ITERATIONS = Integer.parseInt(params[0]);
+ }
+
+ }
+
+
+}
+
Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/zip/ZlibDefsetDictionaryTest.java
------------------------------------------------------------------------------
svn:eol-style = native