Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 39365 invoked from network); 29 Oct 2008 09:10:00 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 29 Oct 2008 09:10:00 -0000 Received: (qmail 240 invoked by uid 500); 29 Oct 2008 09:10:05 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 209 invoked by uid 500); 29 Oct 2008 09:10:05 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 200 invoked by uid 99); 29 Oct 2008 09:10:05 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Oct 2008 02:10:05 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Oct 2008 09:08:59 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id B7ACE2388878; Wed, 29 Oct 2008 02:09:08 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r708840 - /jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/DBDataStoreTest.java Date: Wed, 29 Oct 2008 09:09:08 -0000 To: commits@jackrabbit.apache.org From: jukka@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081029090908.B7ACE2388878@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jukka Date: Wed Oct 29 02:09:07 2008 New Revision: 708840 URL: http://svn.apache.org/viewvc?rev=708840&view=rev Log: JCR-1825: DBDataStore doesn't support concurrent reads Added a DbDataStore test that verifies that many streams can be read concurrently. Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/DBDataStoreTest.java (with props) Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/DBDataStoreTest.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/DBDataStoreTest.java?rev=708840&view=auto ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/DBDataStoreTest.java (added) +++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/DBDataStoreTest.java Wed Oct 29 02:09:07 2008 @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.jackrabbit.core.data; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.InputStream; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Random; + +import junit.framework.TestCase; + +import org.apache.commons.io.FileUtils; +import org.apache.jackrabbit.core.data.db.DbDataStore; + +public class DBDataStoreTest extends TestCase { + + private DbDataStore store = new DbDataStore(); + + private byte[] data = new byte[1024]; + + private DataIdentifier identifier; + + protected void setUp() throws Exception { + FileUtils.deleteQuietly(new File("target/test-db-datastore")); + + // Initialize the data store + store.setUrl("jdbc:derby:target/test-db-datastore/db;create=true"); + store.setDriver("org.apache.derby.jdbc.EmbeddedDriver"); + store.init("target/test-db-datastore"); + + // Initialize random test data + new Random(1234567890).nextBytes(data); + + // Add a test record + identifier = + store.addRecord(new ByteArrayInputStream(data)).getIdentifier(); + } + + protected void tearDow() { + store.close(); + + try { + // TODO: This should automatically be done by DbDataStore.close() + DriverManager.getConnection( + "jdbc:derby:target/test-db-datastore/db;shutdown=true"); + } catch (SQLException expected) { + } + } + + public void testGetRecord() throws Exception { + DataRecord record = store.getRecord(identifier); + assertNotNull(record); + assertEquals(identifier, record.getIdentifier()); + assertEquals(data.length, record.getLength()); + + // read the stream twice to make sure that it can be re-read + for (int i = 0; i < 2; i++) { + InputStream stream = record.getStream(); + try { + assertNotNull(stream); + for (int j = 0; j < data.length; j++) { + assertEquals(((int) data[j]) & 0xff, stream.read()); + } + assertEquals(-1, stream.read()); + } finally { + stream.close(); + } + } + } + + public void testConcurrentRead() throws Exception { + InputStream[] streams = new InputStream[10]; + + // retrieve many copies of the same record + for (int i = 0; i < streams.length; i++) { + streams[i] = store.getRecord(identifier).getStream(); + } + + // verify the contents of all the streams, reading them in parallel + for (int i = 0; i < data.length; i++) { + for (int j = 0; j < streams.length; j++) { + assertEquals(((int) data[i]) & 0xff, streams[j].read()); + } + } + + // close all streams + for (int i = 0; i < streams.length; i++) { + assertEquals(-1, streams[i].read()); + streams[i].close(); + } + } + +} Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/DBDataStoreTest.java ------------------------------------------------------------------------------ svn:eol-style = native