From 5361c5525ed341f5b76bd60f9a42baf3a9457c98 Mon Sep 17 00:00:00 2001 From: Urs Grob <> Date: Tue, 21 Apr 2009 02:07:28 -0700 Subject: AI 147124: am: CL 147120 am: CL 147118 Several fixes to reduce failing tests in the cts host - Removing tests that are placed in a protected package name. They were not part of the cts tests. - Fixing a case of an Exception thrown in the static initializer of GBCharsetEncoderTest. - Remove copy/paste code which led to an exception in a 2nd thread (the test did not fail, but its output was reported in logcat) - fixing a test case in FileTest - removing test code in StmtTest that tested badly specified operations and failed. Original author: ursg Merged from: //branches/cupcake/... Original author: android-build Automated import of CL 147124 --- .../provider/jsse/ClientSessionContextTest.java | 86 ++++++++++++++++ .../harmony/xnet/provider/jsse/FakeSession.java | 114 +++++++++++++++++++++ .../provider/jsse/FileClientSessionCacheTest.java | 57 +++++++++++ .../provider/jsse/ClientSessionContextTest.java | 86 ---------------- .../harmony/xnet/provider/jsse/FakeSession.java | 114 --------------------- .../provider/jsse/FileClientSessionCacheTest.java | 57 ----------- 6 files changed, 257 insertions(+), 257 deletions(-) create mode 100644 x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/ClientSessionContextTest.java create mode 100644 x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/FakeSession.java create mode 100644 x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/FileClientSessionCacheTest.java delete mode 100644 x-net/src/test/java/org/apache/harmony/xnet/provider/jsse/ClientSessionContextTest.java delete mode 100644 x-net/src/test/java/org/apache/harmony/xnet/provider/jsse/FakeSession.java delete mode 100644 x-net/src/test/java/org/apache/harmony/xnet/provider/jsse/FileClientSessionCacheTest.java (limited to 'x-net/src') diff --git a/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/ClientSessionContextTest.java b/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/ClientSessionContextTest.java new file mode 100644 index 0000000..af4490b --- /dev/null +++ b/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/ClientSessionContextTest.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * 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. + */ + +package org.apache.harmony.xnet.provider.jsse; + +import junit.framework.TestCase; + +import javax.net.ssl.SSLSession; +import java.util.Enumeration; +import java.util.Set; +import java.util.HashSet; + +public class ClientSessionContextTest extends TestCase { + + public void testGetSessionById() { + ClientSessionContext context = new ClientSessionContext(null, null); + + SSLSession a = new FakeSession("a"); + SSLSession b = new FakeSession("b"); + + context.putSession(a); + context.putSession(b); + + assertSame(a, context.getSession("a".getBytes())); + assertSame(b, context.getSession("b".getBytes())); + + assertSame(a, context.getSession("a", 443)); + assertSame(b, context.getSession("b", 443)); + + assertEquals(2, context.sessions.size()); + + Set sessions = new HashSet(); + Enumeration ids = context.getIds(); + while (ids.hasMoreElements()) { + sessions.add(context.getSession((byte[]) ids.nextElement())); + } + + Set expected = new HashSet(); + expected.add(a); + expected.add(b); + + assertEquals(expected, sessions); + } + + public void testTrimToSize() { + ClientSessionContext context = new ClientSessionContext(null, null); + + FakeSession a = new FakeSession("a"); + FakeSession b = new FakeSession("b"); + FakeSession c = new FakeSession("c"); + FakeSession d = new FakeSession("d"); + + context.putSession(a); + context.putSession(b); + context.putSession(c); + context.putSession(d); + + context.setSessionCacheSize(2); + + Set sessions = new HashSet(); + Enumeration ids = context.getIds(); + while (ids.hasMoreElements()) { + sessions.add(context.getSession((byte[]) ids.nextElement())); + } + + Set expected = new HashSet(); + expected.add(c); + expected.add(d); + + assertEquals(expected, sessions); + } + +} diff --git a/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/FakeSession.java b/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/FakeSession.java new file mode 100644 index 0000000..4a793dd --- /dev/null +++ b/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/FakeSession.java @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * 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. + */ + +package org.apache.harmony.xnet.provider.jsse; + +import javax.net.ssl.SSLSession; +import javax.net.ssl.SSLSessionContext; +import java.security.cert.Certificate; +import java.security.Principal; + +class FakeSession implements SSLSession { + final String host; + + FakeSession(String host) { + this.host = host; + } + + public int getApplicationBufferSize() { + throw new UnsupportedOperationException(); + } + + public String getCipherSuite() { + throw new UnsupportedOperationException(); + } + + public long getCreationTime() { + throw new UnsupportedOperationException(); + } + + public byte[] getId() { + return host.getBytes(); + } + + public long getLastAccessedTime() { + throw new UnsupportedOperationException(); + } + + public Certificate[] getLocalCertificates() { + throw new UnsupportedOperationException(); + } + + public Principal getLocalPrincipal() { + throw new UnsupportedOperationException(); + } + + public int getPacketBufferSize() { + throw new UnsupportedOperationException(); + } + + public javax.security.cert.X509Certificate[] getPeerCertificateChain() { + throw new UnsupportedOperationException(); + } + + public Certificate[] getPeerCertificates() { + throw new UnsupportedOperationException(); + } + + public String getPeerHost() { + return host; + } + + public int getPeerPort() { + return 443; + } + + public Principal getPeerPrincipal() { + throw new UnsupportedOperationException(); + } + + public String getProtocol() { + throw new UnsupportedOperationException(); + } + + public SSLSessionContext getSessionContext() { + throw new UnsupportedOperationException(); + } + + public Object getValue(String name) { + throw new UnsupportedOperationException(); + } + + public String[] getValueNames() { + throw new UnsupportedOperationException(); + } + + public void invalidate() { + throw new UnsupportedOperationException(); + } + + public boolean isValid() { + throw new UnsupportedOperationException(); + } + + public void putValue(String name, Object value) { + throw new UnsupportedOperationException(); + } + + public void removeValue(String name) { + throw new UnsupportedOperationException(); + } +} diff --git a/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/FileClientSessionCacheTest.java b/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/FileClientSessionCacheTest.java new file mode 100644 index 0000000..ee50863 --- /dev/null +++ b/x-net/src/test/impl/java.injected/org/apache/harmony/xnet/provider/jsse/FileClientSessionCacheTest.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * 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. + */ + +package org.apache.harmony.xnet.provider.jsse; + +import junit.framework.TestCase; + +import java.io.File; +import java.io.IOException; + +public class FileClientSessionCacheTest extends TestCase { + + public void testMaxSize() throws IOException, InterruptedException { + String tmpDir = System.getProperty("java.io.tmpdir"); + if (tmpDir == null) { + fail("Please set 'java.io.tmpdir' system property."); + } + File cacheDir = new File(tmpDir + + "/" + FileClientSessionCacheTest.class.getName() + "/cache"); + final SSLClientSessionCache cache + = FileClientSessionCache.usingDirectory(cacheDir); + Thread[] threads = new Thread[10]; + final int iterations = FileClientSessionCache.MAX_SIZE * 10; + for (int i = 0; i < threads.length; i++) { + final int id = i; + threads[i] = new Thread() { + @Override + public void run() { + for (int i = 0; i < iterations; i++) { + cache.putSessionData(new FakeSession(id + "." + i), + new byte[10]); + } + } + }; + } + for (int i = 0; i < threads.length; i++) { + threads[i].start(); + } + for (int i = 0; i < threads.length; i++) { + threads[i].join(); + } + assertEquals(FileClientSessionCache.MAX_SIZE, cacheDir.list().length); + } +} diff --git a/x-net/src/test/java/org/apache/harmony/xnet/provider/jsse/ClientSessionContextTest.java b/x-net/src/test/java/org/apache/harmony/xnet/provider/jsse/ClientSessionContextTest.java deleted file mode 100644 index af4490b..0000000 --- a/x-net/src/test/java/org/apache/harmony/xnet/provider/jsse/ClientSessionContextTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * 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. - */ - -package org.apache.harmony.xnet.provider.jsse; - -import junit.framework.TestCase; - -import javax.net.ssl.SSLSession; -import java.util.Enumeration; -import java.util.Set; -import java.util.HashSet; - -public class ClientSessionContextTest extends TestCase { - - public void testGetSessionById() { - ClientSessionContext context = new ClientSessionContext(null, null); - - SSLSession a = new FakeSession("a"); - SSLSession b = new FakeSession("b"); - - context.putSession(a); - context.putSession(b); - - assertSame(a, context.getSession("a".getBytes())); - assertSame(b, context.getSession("b".getBytes())); - - assertSame(a, context.getSession("a", 443)); - assertSame(b, context.getSession("b", 443)); - - assertEquals(2, context.sessions.size()); - - Set sessions = new HashSet(); - Enumeration ids = context.getIds(); - while (ids.hasMoreElements()) { - sessions.add(context.getSession((byte[]) ids.nextElement())); - } - - Set expected = new HashSet(); - expected.add(a); - expected.add(b); - - assertEquals(expected, sessions); - } - - public void testTrimToSize() { - ClientSessionContext context = new ClientSessionContext(null, null); - - FakeSession a = new FakeSession("a"); - FakeSession b = new FakeSession("b"); - FakeSession c = new FakeSession("c"); - FakeSession d = new FakeSession("d"); - - context.putSession(a); - context.putSession(b); - context.putSession(c); - context.putSession(d); - - context.setSessionCacheSize(2); - - Set sessions = new HashSet(); - Enumeration ids = context.getIds(); - while (ids.hasMoreElements()) { - sessions.add(context.getSession((byte[]) ids.nextElement())); - } - - Set expected = new HashSet(); - expected.add(c); - expected.add(d); - - assertEquals(expected, sessions); - } - -} diff --git a/x-net/src/test/java/org/apache/harmony/xnet/provider/jsse/FakeSession.java b/x-net/src/test/java/org/apache/harmony/xnet/provider/jsse/FakeSession.java deleted file mode 100644 index 4a793dd..0000000 --- a/x-net/src/test/java/org/apache/harmony/xnet/provider/jsse/FakeSession.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * 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. - */ - -package org.apache.harmony.xnet.provider.jsse; - -import javax.net.ssl.SSLSession; -import javax.net.ssl.SSLSessionContext; -import java.security.cert.Certificate; -import java.security.Principal; - -class FakeSession implements SSLSession { - final String host; - - FakeSession(String host) { - this.host = host; - } - - public int getApplicationBufferSize() { - throw new UnsupportedOperationException(); - } - - public String getCipherSuite() { - throw new UnsupportedOperationException(); - } - - public long getCreationTime() { - throw new UnsupportedOperationException(); - } - - public byte[] getId() { - return host.getBytes(); - } - - public long getLastAccessedTime() { - throw new UnsupportedOperationException(); - } - - public Certificate[] getLocalCertificates() { - throw new UnsupportedOperationException(); - } - - public Principal getLocalPrincipal() { - throw new UnsupportedOperationException(); - } - - public int getPacketBufferSize() { - throw new UnsupportedOperationException(); - } - - public javax.security.cert.X509Certificate[] getPeerCertificateChain() { - throw new UnsupportedOperationException(); - } - - public Certificate[] getPeerCertificates() { - throw new UnsupportedOperationException(); - } - - public String getPeerHost() { - return host; - } - - public int getPeerPort() { - return 443; - } - - public Principal getPeerPrincipal() { - throw new UnsupportedOperationException(); - } - - public String getProtocol() { - throw new UnsupportedOperationException(); - } - - public SSLSessionContext getSessionContext() { - throw new UnsupportedOperationException(); - } - - public Object getValue(String name) { - throw new UnsupportedOperationException(); - } - - public String[] getValueNames() { - throw new UnsupportedOperationException(); - } - - public void invalidate() { - throw new UnsupportedOperationException(); - } - - public boolean isValid() { - throw new UnsupportedOperationException(); - } - - public void putValue(String name, Object value) { - throw new UnsupportedOperationException(); - } - - public void removeValue(String name) { - throw new UnsupportedOperationException(); - } -} diff --git a/x-net/src/test/java/org/apache/harmony/xnet/provider/jsse/FileClientSessionCacheTest.java b/x-net/src/test/java/org/apache/harmony/xnet/provider/jsse/FileClientSessionCacheTest.java deleted file mode 100644 index ee50863..0000000 --- a/x-net/src/test/java/org/apache/harmony/xnet/provider/jsse/FileClientSessionCacheTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * 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. - */ - -package org.apache.harmony.xnet.provider.jsse; - -import junit.framework.TestCase; - -import java.io.File; -import java.io.IOException; - -public class FileClientSessionCacheTest extends TestCase { - - public void testMaxSize() throws IOException, InterruptedException { - String tmpDir = System.getProperty("java.io.tmpdir"); - if (tmpDir == null) { - fail("Please set 'java.io.tmpdir' system property."); - } - File cacheDir = new File(tmpDir - + "/" + FileClientSessionCacheTest.class.getName() + "/cache"); - final SSLClientSessionCache cache - = FileClientSessionCache.usingDirectory(cacheDir); - Thread[] threads = new Thread[10]; - final int iterations = FileClientSessionCache.MAX_SIZE * 10; - for (int i = 0; i < threads.length; i++) { - final int id = i; - threads[i] = new Thread() { - @Override - public void run() { - for (int i = 0; i < iterations; i++) { - cache.putSessionData(new FakeSession(id + "." + i), - new byte[10]); - } - } - }; - } - for (int i = 0; i < threads.length; i++) { - threads[i].start(); - } - for (int i = 0; i < threads.length; i++) { - threads[i].join(); - } - assertEquals(FileClientSessionCache.MAX_SIZE, cacheDir.list().length); - } -} -- cgit v1.1