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 [7/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/reliab...

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/CharBufferSliceTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/CharBufferSliceTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/CharBufferSliceTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/CharBufferSliceTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,172 @@
+/*
+ * 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.2 $
+ */
+
+package org.apache.harmony.test.reliability.api.nio.buffers;
+
+import org.apache.harmony.test.reliability.share.Test;
+import java.nio.CharBuffer;
+import java.util.Random;
+
+/**
+ * Goal: find resource leaks or intermittent failures caused by CharBuffer.slice() / duplicate() / wrap() operations.
+ *
+ * The test does:
+ *    1. Reads parameters, which are:
+ *          param[0] - number of iterations to call/initialize in a cycle
+ *    2. Excutes a cycle of param[0] iterations, on each iteration:
+ *         Allocates 2 char buffers: wrap(CharSequence csq) / wrap(char[] array) 
+ *         For each of the char buffer:
+ *            - sets random position and mark at its position
+ *            - creates slice
+ *            - checks position
+ *            - creates duplicate
+ *            - checks position
+ *            - set random position for the duplicate
+ *            - resets buffer's position to the previously-marked position
+ *            - checks the duplicate position
+ *            - creates duplicate's slice
+ *            - checks position
+ */
+
+public class CharBufferSliceTest extends Test {
+
+    public int NUMBER_OF_ITERATIONS = 1000000;
+
+    final static int size = 1000;
+
+    static int cnt = 0;
+
+    public static void main(String[] args) {
+        System.exit(new CharBufferSliceTest().test(args));
+    }
+
+    public int test(String[] params) {
+
+        parseParams(params);
+
+        String str = "qwertyuiopasdfghjklzxcvbnm";
+        CharBuffer buff1 = null;
+        CharBuffer slice1 = null;
+        CharBuffer buff2 = null;
+        CharBuffer slice2 = null;
+        CharBuffer buff3 = null;
+        CharBuffer slice3 = null;
+        Random rn = new Random();
+        int size = 0;
+        int initial_size = 0;
+
+        for (int i = 0; i < NUMBER_OF_ITERATIONS; i++) {
+            size = rn.nextInt(str.length());
+            buff1 = CharBuffer.wrap(str);
+            buff1.position(size);
+            buff1.mark();
+            initial_size = size;
+            slice1 = buff1.slice();
+
+            if (slice1.position() != 0) {
+                return fail("Iteration " + i
+                    + " : Slice 1 position (should be 0): "
+                    + slice1.position());
+            }
+
+            size = rn.nextInt(str.length());
+            buff3 = buff1.duplicate();
+
+            if (initial_size != buff3.position()) {
+                return fail("Iteration " + i
+                    + " : position after buff1.duplicate(): "
+                    + buff3.position() + " , but should be " + initial_size);
+            }
+
+            buff3.position(size);
+            initial_size = size;
+            buff1.reset();
+
+            if (initial_size != buff3.position()) {
+                return fail("Iteration " + i
+                    + " : position after buff1.reset(): "
+                    + buff3.position() + " , but should be " + initial_size);
+            }
+
+            slice3 = buff3.slice();
+
+            if (slice3.position() != 0) {
+                return fail("Iteration " + i
+                    + " : Slice 3 position (should be 0): "
+                    + slice3.position());
+            }
+
+            size = rn.nextInt(str.length());
+            buff2 = CharBuffer.wrap(str.toCharArray());
+            buff2.position(size);
+            buff2.mark();
+            initial_size = size;
+            slice2 = buff2.slice();
+
+            if (slice2.position() != 0) {
+                return fail("Iteration " + i
+                    + " : Slice 2 position (should be 0): "
+                    + slice2.position());
+            }
+
+            size = rn.nextInt(str.length());
+            buff3 = buff2.duplicate();
+
+            if (initial_size != buff3.position()) {
+                return fail("Iteration " + i
+                    + " : position after buff2.duplicate(): "
+                    + buff3.position() + " , but should be " + initial_size);
+            }
+
+            buff3.position(size);
+            initial_size = size;
+            buff2.reset();
+
+            if (initial_size != buff3.position()) {
+                return fail("Iteration " + i
+                    + " : position after buff2.reset(): "
+                    + buff3.position() + " , but should be " + initial_size);
+            }
+
+            slice3 = buff3.slice();
+
+            if (slice3.position() != 0) {
+                return fail("Iteration " + i
+                    + " : Slice 3 position (should be 0): "
+                    + slice3.position());
+            }
+
+        }
+
+        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/nio/buffers/CharBufferSliceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/CharBufferWrapGetTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/CharBufferWrapGetTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/CharBufferWrapGetTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/CharBufferWrapGetTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,114 @@
+/*
+ * 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.nio.buffers;
+
+import org.apache.harmony.test.reliability.share.Test;
+import java.nio.CharBuffer;
+import java.nio.ByteBuffer;
+import java.util.Random;
+
+
+/**
+ * Goal: find memory leaks caused by CharBuffer.wrap()/put()/get() method.
+ *
+ * The test does:
+ *    1. Reads parameters, which are:
+ *          param[0] - number of iterations to call/initialize one wrap/put/get in a cycle
+
+ *    2. starts a cycle of param[0] iterations. On each iteration:
+ *            - Allocates a random byte buffer
+ *            - puts string into the buffer
+ *            - Sets this buffer's mark at random position
+ *            - wraps a subsequence into the buffer
+ *            - check the result
+ *            - runs System.gc()
+ */
+
+public class CharBufferWrapGetTest extends Test {
+
+    public int callSystemGC = 1;
+
+    public int NUMBER_OF_ITERATIONS = 1000000;
+
+    //private char array
+    private char[] array = new char[0];
+
+    public static void main(String[] args) {
+        System.exit(new CharBufferWrapGetTest().test(args));
+    }
+
+    public int test(String[] params) {
+
+        parseParams(params);
+        String str = "qwertyuiopasdfghjklzxcvbnm1234567890";
+        CharBuffer cbuf = null;
+        CharBuffer subbuf = null;
+        String substr = "";
+        char out[] = {};
+        String cbufstr = "";
+        Random rn = new Random();
+        int size = 0;
+
+        for (int i = 0; i < NUMBER_OF_ITERATIONS; ++i) {
+
+            size = rn.nextInt(str.length());
+            cbuf = CharBuffer.allocate(512 + size);
+            if (i % 2 == 0) {
+                cbuf = ByteBuffer.allocateDirect(512 + size).asCharBuffer();
+            }
+            out = new char[cbuf.length()];
+            cbuf.put(str);
+            cbuf.position(size);
+            cbuf.mark();
+            subbuf = CharBuffer.wrap((CharBuffer)cbuf.subSequence(size, size + 1)); 
+            cbufstr = String.valueOf(cbuf.get(size));
+            out = new char[subbuf.length()];
+            cbuf.get(out);
+            substr = new String(out);
+            cbuf.rewind();
+            if(!substr.equals(cbufstr)) {
+                return fail("Expected on step " + i + " : \"" + substr + "\" but got \"" + cbufstr + "\"");
+            }
+
+            // if (i % 100000 == 0) {
+            //    log.add("Iteration: " + i);
+            // }
+
+
+            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/nio/buffers/CharBufferWrapGetTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/CharBufferWrapTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/CharBufferWrapTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/CharBufferWrapTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/CharBufferWrapTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,86 @@
+/*
+ * 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.nio.buffers;
+
+import org.apache.harmony.test.reliability.share.Test;
+import java.nio.CharBuffer;
+
+/**
+ * Goal: find memory leaks caused by CharBuffer.wrap() method.
+ *
+ * The test does:
+ *    1. Reads parameters, which are:
+ *          param[0] - number of iterations to call/initialize one wrap in a cycle
+ 
+ *    2. CharBuffer.wrap() throws IndexOutOfBoundsException 
+ *    3. starts a cycle of param[0] iterations.
+ *    4. runs System.gc()
+ *
+ */
+
+public class CharBufferWrapTest extends Test {
+
+    public int callSystemGC = 1;
+
+    public int NUMBER_OF_WRAP_ITERATIONS = 10000000;
+
+    //private char array
+    private char[] array = new char[0];
+
+    public static void main(String[] args) {
+        System.exit(new CharBufferWrapTest().test(args));
+    }
+
+    public int test(String[] params) {
+
+        parseParams(params);
+
+        for (int i = 0; i < NUMBER_OF_WRAP_ITERATIONS; ++i) {
+
+            // if (i % 1000000 == 0) {
+            //     log.add("Iteration: " + i);
+            // }
+
+            try {
+                CharBuffer.wrap(array, 1, 2);
+                return fail("CharBuffer.wrap doesn't throw IndexOutOfBoundsException");
+            } catch (IndexOutOfBoundsException e) {
+            }
+
+            if (callSystemGC != 0) {
+                System.gc();
+            }
+        }
+        return pass("OK");
+    }
+
+    public void parseParams(String[] params) {
+
+        if (params.length >= 1) {
+            NUMBER_OF_WRAP_ITERATIONS = Integer.parseInt(params[0]);
+        }
+
+    }
+
+}
+

Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/CharBufferWrapTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/DoubleBufferWrapGetTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/DoubleBufferWrapGetTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/DoubleBufferWrapGetTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/DoubleBufferWrapGetTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,135 @@
+/*
+ * 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.nio.buffers;
+
+
+import org.apache.harmony.test.reliability.share.Test;
+import java.nio.DoubleBuffer;
+import java.nio.ByteOrder;
+import java.nio.ByteBuffer;
+import java.util.Random;
+
+
+/**
+ * Goal: find memory leaks caused by DoubleBuffer.wrap()/allocate() and ByteOrder.nativeOrder() methods.
+ *
+ * The test does:
+ *    1. Reads parameters, which are:
+ *          param[0] - number of iterations to call/initialize one wrap/put/get in a cycle
+ *          param[1] - size of allocated buffer 
+
+ *    2. starts a cycle of param[0] iterations. On each iteration:
+ *            - Allocates a double buffer
+ *            - Allocates a direct byte buffer and creates a view of this byte buffer as a double buffer
+ *            - reverses the native byte order 
+ *            - wraps a double array
+ *            - check the result
+ *            - runs System.gc()
+ */
+
+public class DoubleBufferWrapGetTest extends Test {
+
+    public int callSystemGC = 1;
+
+    public int NUMBER_OF_ITERATIONS = 100000;
+
+    public int BUFFER_SIZE = 100;
+
+    //private char array
+    private char[] array = new char[0];
+
+    public static void main(String[] args) {
+        System.exit(new DoubleBufferWrapGetTest().test(args));
+    }
+
+    public int test(String[] params) {
+
+        parseParams(params);
+
+        for (int i = 0; i < NUMBER_OF_ITERATIONS; ++i) {
+            DoubleBuffer[] array = getDoubleBufferArray();
+            Random rn = new Random();
+            int size = 0;
+            array = getDoubleBufferArray();
+            for(int j = 0; j< array.length ; j++) {
+
+                size = array.length - rn.nextInt(array.length);
+                if(size == 0) {
+                    size = 1;
+                }
+                array[j].limit(size);
+                double[] d = new double[size];
+                d[size -1] = Double.MAX_VALUE;
+                double maxvalue = DoubleBuffer.wrap(d).get(size-1);
+                if(maxvalue != Double.MAX_VALUE) {
+                    return fail("Expected on step " + i + " : \"" + Double.MAX_VALUE + "\" but got \"" + maxvalue + "\"");
+                }
+            }
+
+
+            // if (i % 10000 == 0) {
+            //    log.add("Iteration: " + i);
+            // }
+
+
+            if (callSystemGC != 0) {
+                System.gc();
+            }
+        }
+        return pass("OK");
+    }
+
+    public DoubleBuffer[] getDoubleBufferArray() {
+        DoubleBuffer[] db = new DoubleBuffer[5];
+
+        db[0] = DoubleBuffer.allocate(BUFFER_SIZE); 
+        ByteBuffer bb = ByteBuffer.allocate(BUFFER_SIZE);
+        db[1] = bb.asDoubleBuffer();  
+        db[2] = bb.order(changeOrder()).asDoubleBuffer();
+        ByteBuffer dirbuf = ByteBuffer.allocateDirect(BUFFER_SIZE);
+        db[3] = dirbuf.asDoubleBuffer();
+        db[4] = dirbuf.order(changeOrder()).asDoubleBuffer();
+        return db;
+    }
+
+    public ByteOrder changeOrder() {
+        ByteOrder order = ByteOrder.BIG_ENDIAN;
+        if(ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN) {
+            order = ByteOrder.LITTLE_ENDIAN ;
+        }
+        return order;
+    }
+
+    public void parseParams(String[] params) {
+
+        if (params.length >= 1) {
+            NUMBER_OF_ITERATIONS = Integer.parseInt(params[0]);
+        }
+
+        if (params.length >= 2) {
+            BUFFER_SIZE = Integer.parseInt(params[1]);
+        }
+    }
+
+}
+

Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/DoubleBufferWrapGetTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/FloatBufferWrapGetTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/FloatBufferWrapGetTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/FloatBufferWrapGetTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/FloatBufferWrapGetTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,137 @@
+/*
+ * 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.nio.buffers;
+
+
+import org.apache.harmony.test.reliability.share.Test;
+import java.nio.FloatBuffer;
+import java.nio.ByteOrder;
+import java.nio.ByteBuffer;
+import java.util.Random;
+
+
+/**
+ * Goal: find memory leaks caused by FloatBuffer.wrap()/allocate() and ByteOrder.nativeOrder() methods.
+ *
+ * The test does:
+ *    1. Reads parameters, which are:
+ *          param[0] - number of iterations to call/initialize one wrap/put/get in a cycle
+ *          param[1] - size of allocated buffer 
+
+ *    2. starts a cycle of param[0] iterations. On each iteration:
+ *            - Allocates a Float buffer
+ *            - Allocates a direct byte buffer and creates a view of this byte buffer as a Float buffer
+ *            - reverses the native byte order 
+ *            - wraps a Float array
+ *            - check the result
+ *            - runs System.gc()
+ */
+
+public class FloatBufferWrapGetTest extends Test {
+
+    public int callSystemGC = 1;
+
+    public int NUMBER_OF_ITERATIONS = 100000;
+
+    public int BUFFER_SIZE = 100;
+
+    //private char array
+    private char[] array = new char[0];
+
+    public static void main(String[] args) {
+        System.exit(new FloatBufferWrapGetTest().test(args));
+    }
+
+    public int test(String[] params) {
+
+        parseParams(params);
+
+        for (int i = 0; i < NUMBER_OF_ITERATIONS; ++i) {
+            FloatBuffer[] array = getFloatBufferArray();
+            Random rn = new Random();
+            int size = 0;
+            array = getFloatBufferArray();
+            for(int j = 0; j< array.length ; j++) {
+
+                size = array.length - rn.nextInt(array.length);
+                if(size == 0) {
+                    size = 1;
+                }
+                array[j].limit(size);
+                float[] d = new float[size];
+                d[size -1] = Float.MAX_VALUE;
+                float maxvalue = FloatBuffer.wrap(d).get(size-1);
+                if(maxvalue != Float.MAX_VALUE) {
+                    return fail("Expected on step " + i + " : \"" + Float.MAX_VALUE + "\" but got \"" + maxvalue + "\"");
+                }
+            }
+
+
+            // if (i % 10000 == 0) {
+            //    log.add("Iteration: " + i);
+            // }
+
+
+            if (callSystemGC != 0) {
+                System.gc();
+            }
+        }
+        return pass("OK");
+    }
+
+    public FloatBuffer[] getFloatBufferArray() {
+        FloatBuffer[] db = new FloatBuffer[5];
+
+        db[0] = FloatBuffer.allocate(BUFFER_SIZE); 
+        ByteBuffer bb = ByteBuffer.allocate(BUFFER_SIZE);
+        db[1] = bb.asFloatBuffer();  
+        db[2] = bb.order(changeOrder()).asFloatBuffer();
+        ByteBuffer dirbuf = ByteBuffer.allocateDirect(BUFFER_SIZE);
+        db[3] = dirbuf.asFloatBuffer();
+        db[4] = dirbuf.order(changeOrder()).asFloatBuffer();
+        return db;
+    }
+
+    public ByteOrder changeOrder() {
+        ByteOrder order = ByteOrder.BIG_ENDIAN;
+        if(ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN) {
+            order = ByteOrder.LITTLE_ENDIAN ;
+        }
+        return order;
+    }
+
+    public void parseParams(String[] params) {
+
+        if (params.length >= 1) {
+            NUMBER_OF_ITERATIONS = Integer.parseInt(params[0]);
+        }
+
+        if (params.length >= 2) {
+            BUFFER_SIZE = Integer.parseInt(params[1]);
+        }
+
+    }
+
+
+}
+

Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/FloatBufferWrapGetTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/IntBufferWrapGetTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/IntBufferWrapGetTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/IntBufferWrapGetTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/IntBufferWrapGetTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,137 @@
+/*
+ * 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.nio.buffers;
+
+
+import org.apache.harmony.test.reliability.share.Test;
+import java.nio.IntBuffer;
+import java.nio.ByteOrder;
+import java.nio.ByteBuffer;
+import java.util.Random;
+
+
+/**
+ * Goal: find memory leaks caused by IntBuffer.wrap()/allocate() and ByteOrder.nativeOrder() methods.
+ *
+ * The test does:
+ *    1. Reads parameters, which are:
+ *          param[0] - number of iterations to call/initialize one wrap/put/get in a cycle
+ *          param[1] - size of allocated buffer 
+
+ *    2. starts a cycle of param[0] iterations. On each iteration:
+ *            - Allocates a Int buffer
+ *            - Allocates a direct byte buffer and creates a view of this byte buffer as a Int buffer
+ *            - reverses the native byte order 
+ *            - wraps a Int array
+ *            - check the result
+ *            - runs System.gc()
+ */
+
+public class IntBufferWrapGetTest extends Test {
+
+    public int callSystemGC = 1;
+
+    public int NUMBER_OF_ITERATIONS = 100000;
+
+    public int BUFFER_SIZE = 100;
+
+    //private char array
+    private char[] array = new char[0];
+
+    public static void main(String[] args) {
+        System.exit(new IntBufferWrapGetTest().test(args));
+    }
+
+    public int test(String[] params) {
+
+        parseParams(params);
+
+        for (int i = 0; i < NUMBER_OF_ITERATIONS; ++i) {
+            IntBuffer[] array = getIntBufferArray();
+            Random rn = new Random();
+            int size = 0;
+            array = getIntBufferArray();
+            for(int j = 0; j< array.length ; j++) {
+
+                size = array.length - rn.nextInt(array.length);
+                if(size == 0) {
+                    size = 1;
+                }
+                array[j].limit(size);
+                int[] d = new int[size];
+                d[size -1] = Integer.MAX_VALUE;
+                int maxvalue = IntBuffer.wrap(d).get(size-1);
+                if(maxvalue != Integer.MAX_VALUE) {
+                    return fail("Expected on step " + i + " : \"" + Integer.MAX_VALUE + "\" but got \"" + maxvalue + "\"");
+                }
+            }
+
+
+            // if (i % 10000 == 0) {
+            //    log.add("Iteration: " + i);
+            // }
+
+
+            if (callSystemGC != 0) {
+                System.gc();
+            }
+        }
+        return pass("OK");
+    }
+
+    public IntBuffer[] getIntBufferArray() {
+        IntBuffer[] db = new IntBuffer[5];
+
+        db[0] = IntBuffer.allocate(BUFFER_SIZE); 
+        ByteBuffer bb = ByteBuffer.allocate(BUFFER_SIZE);
+        db[1] = bb.asIntBuffer();  
+        db[2] = bb.order(changeOrder()).asIntBuffer();
+        ByteBuffer dirbuf = ByteBuffer.allocateDirect(BUFFER_SIZE);
+        db[3] = dirbuf.asIntBuffer();
+        db[4] = dirbuf.order(changeOrder()).asIntBuffer();
+        return db;
+    }
+
+    public ByteOrder changeOrder() {
+        ByteOrder order = ByteOrder.BIG_ENDIAN;
+        if(ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN) {
+            order = ByteOrder.LITTLE_ENDIAN ;
+        }
+        return order;
+    }
+
+    public void parseParams(String[] params) {
+
+        if (params.length >= 1) {
+            NUMBER_OF_ITERATIONS = Integer.parseInt(params[0]);
+        }
+
+        if (params.length >= 2) {
+            BUFFER_SIZE = Integer.parseInt(params[1]);
+        }
+
+    }
+
+
+}
+

Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/IntBufferWrapGetTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/LongBufferWrapGetTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/LongBufferWrapGetTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/LongBufferWrapGetTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/LongBufferWrapGetTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,135 @@
+/*
+ * 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.nio.buffers;
+
+import org.apache.harmony.test.reliability.share.Test;
+import java.nio.LongBuffer;
+import java.nio.ByteOrder;
+import java.nio.ByteBuffer;
+import java.util.Random;
+
+
+/**
+ * Goal: find memory leaks caused by LongBuffer.wrap()/allocate() and ByteOrder.nativeOrder() methods.
+ *
+ * The test does:
+ *    1. Reads parameters, which are:
+ *          param[0] - number of iterations to call/initialize one wrap/put/get in a cycle
+ *          param[1] - size of allocated buffer 
+
+ *    2. starts a cycle of param[0] iterations. On each iteration:
+ *            - Allocates a Long buffer
+ *            - Allocates a direct byte buffer and creates a view of this byte buffer as a Long buffer
+ *            - reverses the native byte order 
+ *            - wraps a Long array
+ *            - check the result
+ *            - runs System.gc()
+ */
+
+public class LongBufferWrapGetTest extends Test {
+
+    public int callSystemGC = 1;
+
+    public int NUMBER_OF_ITERATIONS = 100000;
+
+    public int BUFFER_SIZE = 100;
+
+    //private char array
+    private char[] array = new char[0];
+
+    public static void main(String[] args) {
+        System.exit(new LongBufferWrapGetTest().test(args));
+    }
+
+    public int test(String[] params) {
+
+        parseParams(params);
+
+        for (int i = 0; i < NUMBER_OF_ITERATIONS; ++i) {
+            LongBuffer[] array = getLongBufferArray();
+            Random rn = new Random();
+            int size = 0;
+            array = getLongBufferArray();
+            for(int j = 0; j< array.length ; j++) {
+
+                size = array.length - rn.nextInt(array.length);
+                if(size == 0) {
+                    size = 1;
+                }
+                array[j].limit(size);
+                long[] d = new long[size];
+                d[size -1] = Long.MAX_VALUE;
+                long maxvalue = LongBuffer.wrap(d).get(size-1);
+                if(maxvalue != Long.MAX_VALUE) {
+                    return fail("Expected on step " + i + " : \"" + Long.MAX_VALUE + "\" but got \"" + maxvalue + "\"");
+                }
+            }
+
+
+            // if (i % 10000 == 0) {
+            //    log.add("Iteration: " + i);
+            //}
+
+
+            if (callSystemGC != 0) {
+                System.gc();
+            }
+        }
+        return pass("OK");
+    }
+
+    public LongBuffer[] getLongBufferArray() {
+        LongBuffer[] db = new LongBuffer[5];
+
+        db[0] = LongBuffer.allocate(BUFFER_SIZE); 
+        ByteBuffer bb = ByteBuffer.allocate(BUFFER_SIZE);
+        db[1] = bb.asLongBuffer();  
+        db[2] = bb.order(changeOrder()).asLongBuffer();
+        ByteBuffer dirbuf = ByteBuffer.allocateDirect(BUFFER_SIZE);
+        db[3] = dirbuf.asLongBuffer();
+        db[4] = dirbuf.order(changeOrder()).asLongBuffer();
+        return db;
+    }
+
+    public ByteOrder changeOrder() {
+        ByteOrder order = ByteOrder.BIG_ENDIAN;
+        if(ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN) {
+            order = ByteOrder.LITTLE_ENDIAN ;
+        }
+        return order;
+    }
+
+    public void parseParams(String[] params) {
+
+        if (params.length >= 1) {
+            NUMBER_OF_ITERATIONS = Integer.parseInt(params[0]);
+        }
+
+        if (params.length >= 2) {
+            BUFFER_SIZE = Integer.parseInt(params[1]);
+        }
+
+    }
+
+}
+

Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/LongBufferWrapGetTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/ShortBufferWrapGetTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/ShortBufferWrapGetTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/ShortBufferWrapGetTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/ShortBufferWrapGetTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,135 @@
+/*
+ * 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.nio.buffers;
+
+import org.apache.harmony.test.reliability.share.Test;
+import java.nio.ShortBuffer;
+import java.nio.ByteOrder;
+import java.nio.ByteBuffer;
+import java.util.Random;
+
+
+/**
+ * Goal: find memory leaks caused by ShortBuffer.wrap()/allocate() and ByteOrder.nativeOrder() methods.
+ *
+ * The test does:
+ *    1. Reads parameters, which are:
+ *          param[0] - number of iterations to call/initialize one wrap/put/get in a cycle
+ *          param[1] - size of allocated buffer 
+
+ *    2. starts a cycle of param[0] iterations. On each iteration:
+ *            - Allocates a Short buffer
+ *            - Allocates a direct byte buffer and creates a view of this byte buffer as a Short buffer
+ *            - reverses the native byte order 
+ *            - wraps a Short array
+ *            - check the result
+ *            - runs System.gc()
+ */
+
+public class ShortBufferWrapGetTest extends Test {
+
+    public int callSystemGC = 1;
+
+    public int NUMBER_OF_ITERATIONS = 100000;
+
+    public int BUFFER_SIZE = 100;
+
+    //private char array
+    private char[] array = new char[0];
+
+    public static void main(String[] args) {
+        System.exit(new ShortBufferWrapGetTest().test(args));
+    }
+
+    public int test(String[] params) {
+
+        parseParams(params);
+
+        for (int i = 0; i < NUMBER_OF_ITERATIONS; ++i) {
+            ShortBuffer[] array = getShortBufferArray();
+            Random rn = new Random();
+            int size = 0;
+            array = getShortBufferArray();
+            for(int j = 0; j< array.length ; j++) {
+
+                size = array.length - rn.nextInt(array.length);
+                if(size == 0) {
+                    size = 1;
+                }
+                array[j].limit(size);
+                short[] d = new short[size];
+                d[size -1] = Short.MAX_VALUE;
+                short maxvalue = ShortBuffer.wrap(d).get(size-1);
+                if(maxvalue != Short.MAX_VALUE) {
+                    return fail("Expected on step " + i + " : \"" + Short.MAX_VALUE + "\" but got \"" + maxvalue + "\"");
+                }
+            }
+
+
+            // if (i % 10000 == 0) {
+            //    log.add("Iteration: " + i);
+            // }
+
+
+            if (callSystemGC != 0) {
+                System.gc();
+            }
+        }
+        return pass("OK");
+    }
+
+    public ShortBuffer[] getShortBufferArray() {
+        ShortBuffer[] db = new ShortBuffer[5];
+
+        db[0] = ShortBuffer.allocate(BUFFER_SIZE); 
+        ByteBuffer bb = ByteBuffer.allocate(BUFFER_SIZE);
+        db[1] = bb.asShortBuffer();  
+        db[2] = bb.order(changeOrder()).asShortBuffer();
+        ByteBuffer dirbuf = ByteBuffer.allocateDirect(BUFFER_SIZE);
+        db[3] = dirbuf.asShortBuffer();
+        db[4] = dirbuf.order(changeOrder()).asShortBuffer();
+        return db;
+    }
+
+    public ByteOrder changeOrder() {
+        ByteOrder order = ByteOrder.BIG_ENDIAN;
+        if(ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN) {
+            order = ByteOrder.LITTLE_ENDIAN ;
+        }
+        return order;
+    }
+
+    public void parseParams(String[] params) {
+
+        if (params.length >= 1) {
+            NUMBER_OF_ITERATIONS = Integer.parseInt(params[0]);
+        }
+
+        if (params.length >= 2) {
+            BUFFER_SIZE = Integer.parseInt(params[1]);
+        }
+
+    }
+
+}
+

Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/buffers/ShortBufferWrapGetTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/channels/filechannel/ChannelFIOSTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/channels/filechannel/ChannelFIOSTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/channels/filechannel/ChannelFIOSTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/channels/filechannel/ChannelFIOSTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,349 @@
+/*
+ * 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 V. Oleinik
+ * @version $Revision: 1.1 $
+ */
+
+package org.apache.harmony.test.reliability.api.nio.channels.filechannel;
+
+import org.apache.harmony.test.reliability.share.Test;
+
+import java.util.Random;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.File;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileLock;
+import java.nio.ByteBuffer;
+
+
+/**
+ * Goal: check for intermittent errors operating with a file sucessively via FileInputStream and 
+ *       associated channel, FileOutputStream and associated channel.
+ *
+ * Idea: Write into a file via FOS, then channel, then, FOS, then, channel, etc. an array of bytes.
+ *       Then, read from the file via FIS, channel, FIS, channel, etc. Finally, check that read byte
+ *       array has the same content as the original one, thus proving that working via FIS/FOS and
+ *       channels shares input/output state and causes no errors.
+ *
+ * The test does:
+ *
+ *     1. Parses parameters:
+ *             param[0] - a path to an exiting directory where the test can store its files.
+ *
+ *     2. Creates a file with the name param[0]/fileName.
+ *    
+ *     3. Creates FileInputStream, FileOutputStream and associated channels.
+ *
+ *     4. Creates an array of random size (<= SIZE) and fills-in it with random bytes.
+ *
+ *     5. Writes the bytes into the file:
+ *
+ *         a. Splits the byte array into N sub-arrays.
+ *         b. Writes subarrays sequentially via FOS, channel, FOS, channel, etc.
+ *        
+ *     6. Reads bytes from the file by N portions via FIS, channel, FIS, channel, etc.
+ *
+ *     7. Compares initial array and read from the file, expecting they have the same content.
+ *
+ *     8. Truncates created file from 'file size' to 0 successively during N iterations.
+ * 
+ */
+
+public class ChannelFIOSTest extends Test {
+
+    // name of file to write/read byte to/from:
+
+    static final String fileName = "ChannelFIOSTest.file";
+
+    // maximum number of bytes totally to be written into file:
+
+    static final int SIZE = 1000000;
+
+    int actualSize = 0; // will be actual size of the file, a random value
+
+    // number of subarrays to be written / read successively via FOS, channel / FIS, channel:
+
+    static final int N = 50;
+
+    String outputDir = "";
+
+    String workFileName = "";
+
+    FileOutputStream fos = null;
+    FileChannel outChannel = null;
+
+    FileInputStream fis = null;
+    FileChannel inChannel = null;
+
+
+    public static void main(String[] args) {
+        System.exit(new ChannelFIOSTest().test(args));
+    }
+
+
+    public int test(String[] params) {
+
+        File f = null;
+
+        try {
+
+            parseParams(params);
+  
+            f = Utils.createWorkFile(workFileName);
+
+            // Open FIS, FOS and corresponding channels:
+
+            openFISFOSChannels(f);
+                 
+            // Create a byte array of random size which we will play with
+
+            byte[] bytes_to_write = Utils.createRndBytes(getSize());
+
+            // First, we split bytes_to_write array into N equal parts and 
+            // write parts sequntially into the file via FOS, channel, FOS, channel, etc.
+
+            writeBytes(bytes_to_write, f);
+
+            // Second, we read from the file via FIS, channel, FIS, channel, etc.
+
+            byte[] read_bytes = readBytes(f);
+
+            // Third, compare wrote and read bytes.
+  
+            if (!compare(bytes_to_write, read_bytes)) {
+                return fail("Written and read arrays differ...");
+            }
+
+            // Finally, truncate the created file from 'file size' to 0
+            // during N iterations.
+
+            truncateFile();
+
+
+        } catch (Throwable t) {
+            t.printStackTrace();
+            return fail("Exception thrown: " + t);
+
+        } finally {
+
+            try {
+
+                if (fos != null){
+                    fos.close();
+                }
+
+                if (outChannel != null){
+                    outChannel.close();
+                }
+
+                if (fis != null){
+                    fis.close();
+                }
+                if (inChannel != null){
+                    inChannel.close();
+                }
+
+            } catch (Throwable t){
+            }
+
+            if (f != null){
+                f.delete();
+            }
+        }
+
+        return pass("OK");
+    }
+
+
+    // the method truncates the created file from 'file size'  
+    // up to 0 sucessively during N iterations
+
+    void truncateFile() throws Exception {
+
+        long fileSize = outChannel.position(0).size();
+
+        long step = fileSize / N;
+
+        try {
+
+            for (int i = 0; i <= N + 1; ++i) {
+
+                outChannel.truncate(fileSize - step * i);
+
+            }
+
+        } catch (IllegalArgumentException iae) {
+
+            // System.out.println("IAE");
+
+            // this is just in case to check nothing but exception happens 
+            // in case of negative size
+        }
+
+    }
+
+    boolean compare(byte[] b1, byte[] b2){
+
+        if (b1.length != b2.length) {
+            log.add("byte arrays comparison: lengths of arrays are different: " + b1.length + ", " + b2.length);
+            return false;
+        }
+
+        boolean passed = true;
+
+        for (int i = 0; i < b1.length; ++i){
+            if (b1[i] != b2[i]) {
+                log.add("Bytes are different at position " + i + ": " + Byte.toString(b1[i]) + 
+                    " vs. " + Byte.toString(b2[i]));
+                passed = false;
+                break;
+            }
+        }
+
+        return passed;
+    }
+
+
+    // The key method of the test: it reads bytes via FileInputStream, channel,
+    // FileInputStream and channel, etc. expecting that FIS and channel share state,
+    // i.e. reading from channel affects correspondingly FIS and vise versa.
+
+    byte[] readBytes(File f) throws Exception {
+
+        byte[] b_total = new byte[actualSize];
+        int step = actualSize / N;
+
+        byte[] b = new byte[step];
+        ByteBuffer bb = ByteBuffer.allocate(step);
+
+        for (int i = 0; i < N; ++i) {
+                 
+            // READ NEXT PORTION OF BYTES VIA FIS:
+
+            fis.read(b);
+            System.arraycopy(b, 0, b_total, i * step, b.length);
+
+            ++i;
+          
+            if (i < N) {
+
+                bb.clear(); // needed to prepare ByteBuffer for channel read / put operations 
+
+                // READ NEXT PORTION OF BYTES VIA CHANNEL:
+
+                inChannel.read(bb);
+                byte[] arr = bb.array();
+                System.arraycopy(arr, 0, b_total, i * step, arr.length);
+            }
+        }
+
+        return b_total;
+    }
+
+
+    // The key method of the test: it writes bytes via FileOutputStream, channel,
+    // FileOutputStream and channel, etc. expecting that FOS and channel share state,
+    // i.e. writing via channel affects correspondingly FOS and vise versa.
+
+    void writeBytes(byte[] b, File f) throws Exception {
+             
+        ByteBuffer[] bb = splitByteArray(b);
+
+        for (int i = 0; i < bb.length; ++i) {
+
+            // WRITE NEXT PORTION OF BYTES VIA FOS:
+
+            fos.write(bb[i].array()); 
+
+            ++i;
+
+            // WRITE NEXT PORTION OF BYTES VIA CHANNEL:
+
+            if (i < bb.length) {
+                FileLock fl = outChannel.lock();
+                outChannel.write(bb[i]);
+                outChannel.force(false);
+                fl.release();
+            }
+        }
+    }
+
+    // Helpful method which just splits byte array "b" into N equal parts
+    // each part is copied into ByteBuffer (non-direct) and prepared for writing.
+
+    ByteBuffer[] splitByteArray(byte[] b){
+
+        int step = b.length / N;
+
+        ByteBuffer[] bb = new ByteBuffer[N];
+
+        for (int i = 0; i < bb.length; ++i) {
+            bb[i] = ByteBuffer.allocate(step);
+            bb[i].put(b, i * step, step);
+            bb[i].flip(); // needed to prepare ByteBuffer for channel write / get operations
+        }
+
+        return bb;
+    }
+
+
+    // The method just creates FIS, FOS and associated channels
+
+    void openFISFOSChannels(File f) throws Throwable {
+
+        try {
+
+            fos = new FileOutputStream(f);
+            outChannel = fos.getChannel();
+
+            fis = new FileInputStream(f);
+            inChannel = fis.getChannel();
+
+        } catch (Throwable t){
+            log.add(t.toString() +
+                " exception was thrown while creating FileOutputStream or FileInputStream" +
+                " or associated channels for " + f.getPath());
+            throw t;
+        }
+    }
+
+
+    public void parseParams(String[] params) throws Exception {
+
+        // NOTE: outputDir must exist prior to running this test
+
+        if (params.length >= 1) {
+            outputDir =  params[0];
+        } else {
+            throw new Exception("output directory is not specified. Usage: Test <existing output dir name>");
+        }
+        workFileName = outputDir + File.separator + fileName;
+    }
+
+    int getSize() {
+
+        actualSize = (Utils.r.nextInt(SIZE) / N) * N;
+            
+        // log.add("Bytes: " + actualSize);
+
+        return actualSize;
+    }
+
+}

Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/channels/filechannel/ChannelFIOSTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/channels/filechannel/ChannelWriteTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/channels/filechannel/ChannelWriteTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/channels/filechannel/ChannelWriteTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/channels/filechannel/ChannelWriteTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,215 @@
+/*
+ * 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.nio.channels.filechannel;
+
+import org.apache.harmony.test.reliability.share.Test;
+import org.apache.harmony.test.reliability.share.Result;
+
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
+
+/**
+ * The test does:
+ *    1. Reads parameters, which are:
+ *          param[0] - number of threads to run in parallel
+ *          param[1] - allocated size of buffers
+ *          param[2] - number of iterations
+ *          param[3] - size of the byte buffer array
+ *
+ *     2. Starts and, then, joins all started threads
+ *
+ *     3. Checks that in each thread all checks PASSed.
+ *
+ *     4. Each thread, being started:
+ *
+ *         In each of param[2] iterations:
+ *           - creates FileChannel object associated with file output stream
+ *           - allocates some param[3] byte buffers.
+ *           - writes a sequence of bytes to this channel from the given buffers.
+ *           - Calls System.gc()
+ */
+
+
+public class ChannelWriteTest extends Test {
+
+    public int NUMBER_OF_ITERATIONS = 1000;
+
+    // size of the byte buffer array
+    public int NUMBER_OF_BYTE_BUFFERS = 1;
+
+    // How much bytes to read from the input file into byte array
+    public int bufferSize = 1024;
+
+    // Number of threads to run in parallel
+    public int numThreads = 1;
+
+    public int callSystemGC = 1;
+
+    // Each thread sets PASS/FAIL flag into its corresponding array element
+    public int[] statuses;
+
+    // Number bytes to write into the buffer
+    public int write_byte =50;
+
+
+    public static void main(String[] args) {
+        System.exit(new ChannelWriteTest().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 ChannelWriteThread(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] != Result.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 && Integer.parseInt(params[0]) > 0) {
+            numThreads = Integer.parseInt(params[0]);
+        }        
+
+
+        if (params.length >= 2) {
+            bufferSize= Integer.parseInt(params[1]);
+        }        
+
+        if (params.length >= 3) {
+            NUMBER_OF_ITERATIONS = Integer.parseInt(params[2]);
+        }        
+
+        if (params.length >= 4) {
+            NUMBER_OF_BYTE_BUFFERS = Integer.parseInt(params[3]);
+        }        
+
+    }
+
+}
+
+
+class ChannelWriteThread implements Runnable {
+
+    public int id;
+    public ChannelWriteTest base;
+
+    public ChannelWriteThread(int id, ChannelWriteTest base) {
+        this.id = id;
+        this.base = base;
+    }
+
+    public void run() {
+        FileOutputStream fos = null;
+        FileChannel channel = null;
+
+        try {
+            File file = File.createTempFile("test", null);
+            file.deleteOnExit();
+            fos = new FileOutputStream(file);
+            channel = fos.getChannel();
+        } catch (IOException e) {
+            e.printStackTrace();
+        } 
+        base.statuses[id] = Result.PASS;
+        ByteBuffer[] buffer = new ByteBuffer[base.NUMBER_OF_BYTE_BUFFERS];
+
+        for (int i = 0; i < base.NUMBER_OF_ITERATIONS; ++i) {
+            for(int j = 0; j < base.NUMBER_OF_BYTE_BUFFERS; j++) {
+                buffer[j] = ByteBuffer.allocate(2*base.bufferSize); 
+                putByte(buffer[j], base.write_byte);
+                buffer[j].flip(); 
+            }
+
+            try {
+                channel.write(buffer);  
+            } catch (IOException e) {
+                base.statuses[id] = Result.FAIL;
+                base.log.add("Thread " + id + " : IOException while buffer writing");
+            }
+
+            for(int j = 0; j < base.NUMBER_OF_BYTE_BUFFERS; j++) {
+                buffer[j].clear();
+            }
+
+            if (base.callSystemGC != 0){
+                System.gc();
+            }
+        }
+        try {
+            channel.close();
+            fos.close();
+        } catch (IOException e) {
+            base.statuses[id] = Result.FAIL;
+            base.log.add("Thread " + id + " : IOException while closing");
+        }
+    }
+
+    public void putByte(ByteBuffer buf, int cnt) {
+        for (int i=0; i < cnt; i++ ){
+            buf.put( (byte) i);
+            buf.put( (byte) '\n');
+        }
+    }
+
+
+}
+

Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/channels/filechannel/ChannelWriteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/channels/filechannel/CopyFilesTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/channels/filechannel/CopyFilesTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/channels/filechannel/CopyFilesTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/channels/filechannel/CopyFilesTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,372 @@
+/*
+ * 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 V. Oleinik
+ * @version $Revision: 1.1 $
+ */
+
+package org.apache.harmony.test.reliability.api.nio.channels.filechannel;
+
+import org.apache.harmony.test.reliability.share.Test;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileInputStream;
+import java.nio.channels.FileChannel;
+import java.nio.ByteBuffer;
+
+
+/**
+ * Goal: check FileChannel transferFrom/To operations work correctly.
+ *
+ * Idea: Create a file with random content, then, many threads copy the file
+ *       via transferFrom/To, each into its own file.
+ *
+ * The test does:
+ *
+ *     1. Parses parameters:
+ *             param[0] - a path to an exiting directory where the test can store its files.
+ *
+ *     2. Creates a file with the name param[0]/fileName, fills it in with FILE_SIZE random bytes.
+ *    
+ *     3. Starts N_OF_THREADS threads, each thread:
+ *
+ *          a. Transfers from original file's channel FILE_SIZE/2 bytes into copy file.
+ *
+ *          b. Transfers to the copy file's channel the rest of FILE_SIZE/2 bytes from the
+ *             original file's channel.
+ *        
+ *     4. Checks the size of each copy file is equal to the original file.
+ *
+ *     7. Closes channels and deletes all created files.
+ * 
+ */
+
+
+public class CopyFilesTest extends Test {
+
+    // Size of the original file and hence of each file's copy
+
+    static final int FILE_SIZE = 100000;
+
+    // Number of copying threads, i.e. copy files
+
+    static final int N_OF_THREADS = 10;
+
+
+    volatile boolean passed = true;
+
+    String workFileName = "";
+  
+    String fileName = "CopyFilesTest.file";
+
+    String outputDir = "";
+
+
+    public static void main(String[] args) {
+        System.exit(new CopyFilesTest().test(args));
+    }
+
+
+    public int test(String[] params) {
+
+        File f_from = null;
+
+        passed = true;
+
+        try {
+
+            parseParams(params);
+
+            // First, create work file
+            f_from = Utils.createWorkFile(workFileName);
+
+
+            // Second, fill it in with random byte values
+            fillInFile(f_from);
+
+
+            // Third, run threads each copying the file into another file
+            copy(f_from);
+
+
+            // Finally, remove the created work file and return appropriate status
+            if (!passed) {
+                return fail("Failed");
+            }
+
+
+        } catch (Throwable t) {
+
+            t.printStackTrace();
+
+            return fail("Exception thrown: " + t);
+
+        } finally {
+
+            if (f_from != null) {
+                f_from.delete();
+            }
+        }
+
+        return pass("OK");
+    }
+
+
+
+    // The method just fills-in the file 'f' with random byte values
+
+    void fillInFile(File f) throws Exception {
+
+        FileChannel fc = null;
+
+        try {
+
+            fc = new FileOutputStream(f).getChannel();
+
+            byte[] b = Utils.createRndBytes(FILE_SIZE);
+
+            ByteBuffer bb = ByteBuffer.allocateDirect(b.length).wrap(b);
+
+            fc.write(bb);
+
+            fc.force(false);
+
+        } finally {
+
+            if (fc != null) { 
+                fc.close();
+            }
+        }
+
+        return;
+    }
+
+
+    // The key method - runs N_OF_THREADS threads, passing to each a channel
+    // from and to which copy the content, waits for threads' finishing and checks
+    // files' sizes.
+ 
+    void copy(File f_from) throws Exception {
+            
+        Thread[] t = new Thread[N_OF_THREADS];
+
+        File[] f_to = new File[N_OF_THREADS];
+
+        FileChannel[] outChannels = new FileChannel[N_OF_THREADS];
+
+        FileChannel inChannel = null;
+
+        try {
+
+            // First, open a read-only channel of original file
+
+            inChannel = new FileInputStream(f_from).getChannel();
+
+            for (int i = 0; i < t.length; ++i) {
+
+                // Second, create files to copy the original file to
+
+                f_to[i] = new File(f_from.getAbsolutePath() + "_copy_" + i);
+
+                // Third, create write-only channels to copy bytes to
+
+                outChannels[i] = new FileOutputStream(f_to[i]).getChannel();
+
+                // Forth, create and run threads, each copying from inChannel 
+                // into its outChannel[i]
+
+                t[i] = new Copier("" + i, inChannel, outChannels[i], this);
+
+                t[i].start();
+            }
+ 
+            // Fifth, wait threads for finishing
+
+            for (int i = 0; i < t.length; ++i) {
+                t[i].join();
+            }
+
+            // Finally, is there were no errors, check that content of the original
+            // file is equal to the copies
+                               
+            if (passed) {
+ 
+                for (int i = 0; i < f_to.length; ++i) {
+
+                    if (!checkContent(f_from, f_to[i])) {
+
+                        passed = false;
+
+                    }
+                }
+            }
+
+        } catch (Throwable tr) {
+
+            tr.printStackTrace();
+
+            log.add("Exception thrown: " + tr);
+
+            passed = false;
+
+        } finally {
+
+            // Actually, this is final action - we close all channels 
+            // and delete all created files-copies:
+
+            if (inChannel != null){
+                inChannel.close();
+            }
+
+            for (int i = 0; i < outChannels.length; ++i) {
+
+                if (outChannels[i] != null) {
+                    outChannels[i].close();
+                }
+
+                if (f_to[i] != null) {
+                    f_to[i].delete();
+                }
+            }
+        }
+
+        return;
+    }
+
+
+    // Just checks that sizes of two files are the same
+
+    boolean checkContent(File f1, File f2) {
+            
+        if (f1.length() != f2.length()) {
+
+            log.add("Size of " + f1.getName() + " is " + f1.length() + ", while size of " + 
+                f2.getName() + " is " + f2.length());
+
+            return false;
+        }
+
+        return true;
+    }
+
+
+    public void parseParams(String[] params) throws Exception {
+
+        // NOTE: outputDir must exist prior to running this test
+
+        if (params.length >= 1) {
+            outputDir =  params[0];
+        } else {
+            throw new Exception("output directory is not specified. Usage: Test <existing output dir name>");
+        }
+
+        workFileName = outputDir + File.separator + fileName;
+    }
+
+}
+
+
+
+
+class Copier extends Thread {
+
+    FileChannel from = null, to = null;
+
+    CopyFilesTest base = null;
+
+
+    Copier (String id, FileChannel from, FileChannel to, CopyFilesTest base) {
+        super(id);
+        this.from = from;
+        this.to = to;
+        this.base = base; // needed to log failures
+    }
+
+
+    public void run() {
+
+        long size = 0l, transfered = 0l;
+
+        try {
+
+            // First, a lock upon input channel must be aquired - experimants show
+            // operation transferFrom/To is not thread safe
+
+            synchronized (from) {
+
+                Thread.yield();
+
+                // transferFrom/To is not completely thread-safe, we set-up position to 0 explicitely
+
+                from.position(0); 
+
+                // we will transfer by 2 equal portions: 0..size/2 and size/2..size
+
+                size = from.size() / 2; 
+
+                Thread.yield();
+
+                // TESTED METHOD CALL - transferFrom
+
+                transfered = to.transferFrom(from, 0, size);
+
+                if (transfered != size) {
+
+                    base.log.add("Thread " + this.getName() + ": transferFrom transfered " + 
+                        transfered + " bytes, instead of expected " + size + " bytes");
+
+                    base.passed = false;
+   
+                }
+
+                to.force(false);
+
+                // transferFrom/To is not completely thread-safe, we set-up position to the middle 
+                // of file explicitely
+
+                to.position(size);
+
+                // TESTED METHOD CALL - transferTo
+
+                transfered = from.transferTo(size, size, to);
+
+                if (transfered != size) {
+
+                    base.log.add("Thread " + this.getName() + ": transferTo transfered " + 
+                        transfered + " bytes, instead of expected " + size + " bytes");
+
+                    base.passed = false;
+   
+                }
+
+                to.force(false);
+            }
+
+
+        } catch (Exception e) {
+
+            e.printStackTrace();
+
+            base.log.add("Thread " + this.getName() + ": " + e + " while transferFrom/To() operation");
+
+            base.passed = false;
+        }
+    }
+
+}

Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/channels/filechannel/CopyFilesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/channels/filechannel/FileChannelMapTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/channels/filechannel/FileChannelMapTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/channels/filechannel/FileChannelMapTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/channels/filechannel/FileChannelMapTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,208 @@
+/*
+ * 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.2 $
+ */
+
+package org.apache.harmony.test.reliability.api.nio.channels.filechannel;
+
+import org.apache.harmony.test.reliability.share.Test;
+import org.apache.harmony.test.reliability.share.Result;
+
+import java.io.File;
+import java.io.RandomAccessFile;
+import java.io.IOException;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileChannel.MapMode;
+
+/**
+ * The test does: 
+ * 1. Reads parameters, which are: 
+ *        param[0] - number of threads to run in parallel 
+ *        param[1] - directory where input file is located 
+ *        param[2] - constant for offset within the file 
+ *        param[3] - input file name 
+ *        param[4] - number of iterations each thread does
+ * 
+ * 2. Starts and, then, joins all started threads
+ * 
+ * 3. Checks that in each thread all checks PASSed.
+ * 
+ * 4. Each thread, being started:
+ * 
+ * a. Reads content from input of RandomAccess file (param[1] + "/" + param[3])
+ * to a file channel for mapping into memory
+ * 
+ * b. In each of param[4] iterations: - maps region of this channel's file
+ * directly into memory - the position within the file at which the mapped
+ * region is random
+ */
+
+public class FileChannelMapTest extends Test {
+
+    // Each thread does NUMBER_OF_ITERATIONS mapping operations
+    public int NUMBER_OF_ITERATIONS = 1000;
+
+    // Directory where input file is located
+    public String path_to_file;
+
+    // Input file name
+    public String fileName = "Test.out";
+
+    // constant for offset within the file
+    public int offsetSize = 512;
+
+    // Number of threads to run in parallel
+    public int numThreads = 5;
+
+    public int callSystemGC = 1;
+
+    // Each thread sets PASS/FAIL flag into its corresponding array element
+    public int[] statuses;
+
+    public static void main(String[] args) {
+        System.exit(new FileChannelMapTest().test(args));
+    }
+
+    public int test(String[] params) {
+
+        parseParams(params);
+
+        // Start 'numThreads' threads each reading from file
+
+        Thread[] t = new Thread[numThreads];
+
+        statuses = new int[t.length];
+
+        for (int i = 0; i < t.length; i++) {
+            t[i] = new Thread(new FileChannelThread(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] != Result.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 && Integer.parseInt(params[0]) > 0) {
+            numThreads = Integer.parseInt(params[0]);
+        }
+
+        if (params.length >= 2) {
+            path_to_file = params[1];
+        }
+
+        if (params.length >= 3) {
+            offsetSize = Integer.parseInt(params[2]);
+        }
+
+        if (params.length >= 4) {
+            fileName = params[3];
+        }
+
+        if (params.length >= 5) {
+            NUMBER_OF_ITERATIONS = Integer.parseInt(params[4]);
+        }
+
+    }
+
+}
+
+class FileChannelThread implements Runnable {
+
+    public int id;
+
+    public FileChannelMapTest base;
+
+    public FileChannelThread(int id, FileChannelMapTest base) {
+        this.id = id;
+        this.base = base;
+    }
+
+    FileChannel getFileChannelFromFile(String fileName) {
+        File f = null;
+        FileChannel fc = null;
+        try {
+            f = new File(fileName);
+            fc = new RandomAccessFile(f, "r").getChannel();
+        } catch (IOException e) {
+            base.statuses[id] = Result.FAIL;
+            base.log.add("Thread " + id + ": IOException on RandomAccessFile creation");
+            return null;
+        }
+        return fc;
+    }
+
+    public void run() {
+
+        FileChannel.MapMode mode = FileChannel.MapMode.READ_ONLY;
+        FileChannel fc = getFileChannelFromFile(base.path_to_file
+            + File.separator + base.fileName);
+        if (fc == null) {
+            return;
+        }
+        long s = 0;
+        try {
+            s = fc.size();
+        } catch (IOException e) {
+            base.statuses[id] = Result.FAIL;
+            base.log.add("Thread " + id + ": IOException while getting size of channel's file");
+            return;
+        }
+        for (int i = 0; i < base.NUMBER_OF_ITERATIONS; i++) {
+            try {
+                base.statuses[id] = Result.FAIL;
+                long offset = (long) (Math.random() * s);
+                fc.map(mode, Math.min(s - base.offsetSize, offset),
+                    base.offsetSize);
+                base.statuses[id] = Result.PASS;
+            } catch (IOException e) {
+                base.statuses[id] = Result.FAIL;
+                base.log.add("Thread " + id + ", iteration " + i + ": IOException while mapping");
+                return;
+            }
+            if (base.callSystemGC != 0){
+                System.gc();
+            }
+
+        }
+    }
+}

Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/channels/filechannel/FileChannelMapTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/channels/filechannel/FileChannelThrSafetyTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/channels/filechannel/FileChannelThrSafetyTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/channels/filechannel/FileChannelThrSafetyTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/channels/filechannel/FileChannelThrSafetyTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,304 @@
+/*
+ * 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 V. Oleinik
+ * @version $Revision: 1.1 $
+ */
+
+package org.apache.harmony.test.reliability.api.nio.channels.filechannel;
+
+import org.apache.harmony.test.reliability.share.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.FileOutputStream;
+import java.io.FileInputStream;
+import java.io.RandomAccessFile;
+import java.nio.channels.FileChannel;
+import java.nio.ByteBuffer;
+import java.nio.MappedByteBuffer;
+
+
+/**
+ * Goal: check FileChannel write operation for thread safety.
+ *
+ * Idea: Several threads write into a FileChannel equal size chunks of bytes each starting 
+ *       and ending with MARK byte. If write operations are thread unsafe, then chunks 
+ *       will be mixed.
+ *
+ * The test does:
+ *
+ *     1. Parses parameters:
+ *             param[0] - a path to an exiting directory where the test can store its files.
+ *
+ *     2. Creates a file with the name param[0]/fileName.
+ *    
+ *     3. Creates FileInputStream, FileOutputStream and associated channels.
+ *
+ *     4. Starts N_OF_THREADS threads, each thread:
+ *
+ *          a. Creates N_OF_BUFFERS_PER_WRITE byte arrays of (CHUNK_SIZE + 2) size,
+ *            each wrapped into direct ByteBuffer.
+ *
+ *          b. Writes the chunks.
+ *
+ *          c. Repeates the opration N_OF_WRITES_PER_THREAD times.
+ *        
+ *     6. Checks the content of the file: reads bytes from the file by (CHUNK_SIZE + 2) 
+ *        chunks, checks that first and last bytes of each read chunk is MARK.
+ *
+ *     7. Closes channels.
+ * 
+ */
+
+public class FileChannelThrSafetyTest extends Test {
+
+
+    // each written chunk has has size (CHUNK_SIZE + 2) 
+    // and content {MARK, <random bytes>, MARK}
+
+    static final int CHUNK_SIZE = 2000;
+
+
+    // Each thread repeats writing into a channel N_OF_WRITES_PER_THREAD times
+
+    static final int N_OF_WRITES_PER_THREAD = 20;
+
+
+    // Each write operation is called with N_OF_BUFFERS_PER_WRITE ByteBuffers
+
+    static final int N_OF_BUFFERS_PER_WRITE = 20;
+
+
+    // Mark-up byte value
+
+    static final byte MARK = 0x22;
+
+
+    // Number of byte-writing threads to run
+ 
+    static final int N_OF_THREADS = 10;
+
+
+    boolean passed = true;
+
+    String workFileName = "";
+  
+    String fileName = "FileChannelThrSafetyTest.file";
+
+    String outputDir = "";
+
+    FileChannel outChannel = null, inChannel = null;
+
+
+    public static void main(String[] args) {
+        System.exit(new FileChannelThrSafetyTest().test(args));
+    }
+
+
+    public int test(String[] params) {
+
+        File f = null;
+
+        passed = true;
+
+        try {
+
+            parseParams(params);
+
+            f = Utils.createWorkFile(workFileName);
+
+            outChannel = new FileOutputStream(f).getChannel();
+
+            inChannel = new FileInputStream(f).getChannel();
+
+            runThreads();
+
+            if (!passed || !checkWrittenContent()) {
+                return fail("Failed");
+            }
+
+        } catch (Throwable t) {
+
+            t.printStackTrace();
+
+            return fail("Exception thrown: " + t);
+
+        } finally {
+
+            try {
+
+                if (outChannel != null){
+                    outChannel.close();
+                }
+
+                if (inChannel != null){
+                    inChannel.close();
+                }
+                    
+            } catch (Throwable t){
+            }
+
+            if (f != null){
+                f.delete();
+            }
+        }
+
+        return pass("OK");
+    }
+
+
+    // Reads from inChannel by (CHUNK_SIZE + 2) chunks, checks the first and last 
+    // bytes are MARK bytes.
+
+    boolean checkWrittenContent() throws Exception {
+
+        MappedByteBuffer mp = null;
+
+        int steps = N_OF_WRITES_PER_THREAD * N_OF_THREADS * N_OF_BUFFERS_PER_WRITE;
+
+        int size = (CHUNK_SIZE + 2);
+
+        ByteBuffer bb = ByteBuffer.allocate(size); 
+
+        for (int i = 0; i < steps; ++i) {
+
+            bb.clear();
+
+            inChannel.read(bb);
+
+            byte first = bb.get(0);
+
+            byte last = bb.get(bb.capacity() - 1);
+
+            if (first != MARK || last != MARK) {
+
+                log.add("Channel writing is thread-unsafe? - Chunk # " + i + ": first byte is " +
+                    first + ", last byte is " + last + ", While " + MARK + 
+                    " byte is expected for each.");
+
+                return false;
+            }
+
+        }
+
+        return true;
+    }
+
+ 
+    void runThreads() throws Exception {
+
+        Thread[] t = new Thread[N_OF_THREADS];
+
+        for (int i = 0; i < t.length; ++i) {
+            t[i] = new ChunkWriter(this); 
+            t[i].start();
+        }
+
+        for (int i = 0; i < t.length; ++i) {
+            t[i].join();
+        }
+    }
+
+
+    public void parseParams(String[] params) throws Exception {
+
+        // NOTE: outputDir must exist prior to running this test
+
+        if (params.length >= 1) {
+            outputDir =  params[0];
+        } else {
+            throw new Exception("output directory is not specified. Usage: Test <existing output dir name>");
+        }
+        workFileName = outputDir + File.separator + fileName;
+    }
+
+}
+
+
+
+
+class ChunkWriter extends Thread {
+
+    FileChannel outChannel = null;
+
+    FileChannelThrSafetyTest base = null;
+
+
+    ChunkWriter(FileChannelThrSafetyTest base) {
+
+        this.outChannel = base.outChannel;
+
+        this.base = base;
+    }
+
+
+    public void run () {
+
+        try {
+
+            for (int i = 0; i < FileChannelThrSafetyTest.N_OF_WRITES_PER_THREAD; ++i) {
+
+                long written = outChannel.write(createByteChunks());
+
+                // base.log.add("Bytes written " + written);
+
+                Thread.yield();
+
+                Thread.sleep(10);
+            }
+
+            outChannel.force(false);
+
+        } catch (Exception e){
+            base.log.add("Thread " + Thread.currentThread().getId() + ": Exception \"" + e + 
+                "\", while writing ByteBuffer[] into channel");
+            base.passed = false;
+        }
+    }
+
+
+    ByteBuffer[] createByteChunks() {
+
+        ByteBuffer[] bb_arr = new ByteBuffer[FileChannelThrSafetyTest.N_OF_BUFFERS_PER_WRITE];
+
+        for (int i = 0; i < bb_arr.length; ++i) {
+            bb_arr[i] = createByteChunk();
+        }
+       
+        return bb_arr;
+    }
+
+
+    ByteBuffer createByteChunk() {
+
+        byte[] exclusion_bytes = new byte[] {FileChannelThrSafetyTest.MARK, FileChannelThrSafetyTest.MARK};
+
+        byte[] b = Utils.createRndBytes(FileChannelThrSafetyTest.CHUNK_SIZE + 2, exclusion_bytes);
+
+        b[0] = FileChannelThrSafetyTest.MARK;
+  
+        b[b.length - 1] = b[0];
+
+        ByteBuffer bb = ByteBuffer.allocateDirect(b.length).wrap(b);
+
+        return bb;
+    }
+
+}
+

Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/channels/filechannel/FileChannelThrSafetyTest.java
------------------------------------------------------------------------------
    svn:eol-style = native