You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by rv...@apache.org on 2013/08/27 01:33:47 UTC
svn commit: r1517729 - in
/jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/core:
TS_Core.java TestDatasetGraphWithLock.java
Author: rvesse
Date: Mon Aug 26 23:33:47 2013
New Revision: 1517729
URL: http://svn.apache.org/r1517729
Log:
Regression tests for JENA-522
Added:
jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/core/TestDatasetGraphWithLock.java
Modified:
jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/core/TS_Core.java
Modified: jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/core/TS_Core.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/core/TS_Core.java?rev=1517729&r1=1517728&r2=1517729&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/core/TS_Core.java (original)
+++ jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/core/TS_Core.java Mon Aug 26 23:33:47 2013
@@ -32,6 +32,7 @@ import org.junit.runners.Suite ;
, TestGraphOverDatasetMem.class
, TestDatasetGraphViewGraphs.class
, TestDatasetMonitor.class
+ , TestDatasetGraphWithLock.class
})
public class TS_Core
Added: jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/core/TestDatasetGraphWithLock.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/core/TestDatasetGraphWithLock.java?rev=1517729&view=auto
==============================================================================
--- jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/core/TestDatasetGraphWithLock.java (added)
+++ jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/core/TestDatasetGraphWithLock.java Mon Aug 26 23:33:47 2013
@@ -0,0 +1,122 @@
+/*
+ * 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 com.hp.hpl.jena.sparql.core;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.query.DatasetFactory;
+import com.hp.hpl.jena.query.ReadWrite;
+
+public class TestDatasetGraphWithLock extends AbstractTestDataset {
+
+ @Override
+ protected Dataset createFixed() {
+ return DatasetFactory.create(new DatasetGraphWithLock(DatasetGraphFactory.createMem()));
+ }
+
+ @Test
+ public synchronized void dsg_with_lock_concurrency_01() throws InterruptedException, ExecutionException, TimeoutException {
+ ExecutorService executor = Executors.newFixedThreadPool(2);
+
+ try {
+ final DatasetGraphWithLock dsg = new DatasetGraphWithLock(DatasetGraphFactory.createMem());
+
+ Callable<Boolean> callable = new Callable<Boolean>() {
+
+ @Override
+ public Boolean call() throws Exception {
+ dsg.begin(ReadWrite.READ);
+
+ // Hold the lock for a few seconds
+ try {
+ Thread.sleep(3000);
+ } catch (InterruptedException e) {
+ // Ignore error
+ }
+
+ dsg.commit();
+ return true;
+ }
+
+ };
+
+ // Fire off two threads
+ Future<Boolean> f1 = executor.submit(callable);
+ Future<Boolean> f2 = executor.submit(callable);
+ Assert.assertTrue(f1.get(4, TimeUnit.SECONDS));
+ Assert.assertTrue(f2.get(4, TimeUnit.SECONDS));
+ } finally {
+ executor.shutdownNow();
+ }
+ }
+
+ @Test
+ public synchronized void dsg_with_lock_concurrency_02() throws InterruptedException, ExecutionException, TimeoutException {
+ ExecutorService executor = Executors.newCachedThreadPool();
+
+ try {
+ final DatasetGraphWithLock dsg = new DatasetGraphWithLock(DatasetGraphFactory.createMem());
+
+ Callable<Boolean> callable = new Callable<Boolean>() {
+
+ @Override
+ public Boolean call() throws Exception {
+ dsg.begin(ReadWrite.READ);
+
+ // Hold the lock for a few seconds
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ // Ignore error
+ }
+
+ dsg.commit();
+ return true;
+ }
+
+ };
+
+ // Run the callable a bunch of times
+ List<Future<Boolean>> futures = new ArrayList<Future<Boolean>>();
+ for (int i = 0; i < 100; i++) {
+ futures.add(executor.submit(callable));
+ }
+
+ // Check all the futures come back OK
+ for (Future<Boolean> f : futures) {
+ Assert.assertTrue(f.get(3, TimeUnit.SECONDS));
+ }
+ } finally {
+ executor.shutdownNow();
+ }
+ }
+
+}