Package com.hp.hpl.jena.tdb

Examples of com.hp.hpl.jena.tdb.StoreConnection


    // Basics.
   
    @Test public void trans_01()
    {
        StoreConnection sConn = getStoreConnection() ;
        DatasetGraphTxn dsg = sConn.begin(ReadWrite.READ) ;
        dsg.end() ;
    }
View Full Code Here


    }
   

    @Test public void trans_02()
    {
        StoreConnection sConn = getStoreConnection() ;
        DatasetGraphTxn dsg = sConn.begin(ReadWrite.WRITE) ;
        try {
            dsg.add(q) ;
            assertTrue(dsg.contains(q)) ;
            dsg.commit() ;
        } finally { dsg.end() ; }
View Full Code Here

    }
   
    @Test public void trans_03()
    {
        // WRITE-commit-READ-check
        StoreConnection sConn = getStoreConnection() ;
        DatasetGraphTxn dsgW = sConn.begin(ReadWrite.WRITE) ;
       
        dsgW.add(q) ;
        assertTrue(dsgW.contains(q)) ;
        dsgW.commit() ;
        dsgW.end() ;
       
        DatasetGraphTxn dsg2 = sConn.begin(ReadWrite.READ) ;
        assertTrue(dsg2.contains(q)) ;
        dsg2.end() ;
       
        DatasetGraph dsg = sConn.getBaseDataset() ;
        assertTrue(dsg.contains(q)) ;
       
    }
View Full Code Here

    }
   
    @Test public void trans_04()
    {
        // WRITE-abort-READ-check
        StoreConnection sConn = getStoreConnection() ;
        DatasetGraphTxn dsgW = sConn.begin(ReadWrite.WRITE) ;
       
        dsgW.add(q) ;
        assertTrue(dsgW.contains(q)) ;
        dsgW.abort() ;
        dsgW.end() ;
       
        DatasetGraphTxn dsg2 = sConn.begin(ReadWrite.READ) ;
        assertFalse(dsg2.contains(q)) ;
        dsg2.end() ;
       
        DatasetGraph dsg = sConn.getBaseDataset() ;
        assertFalse(dsg.contains(q)) ;
    }
View Full Code Here

    }
   
    @Test public void trans_05()
    {
        // WRITE(commit)-WRITE(commit)-READ-check
        StoreConnection sConn = getStoreConnection() ;
        DatasetGraphTxn dsgW1 = sConn.begin(ReadWrite.WRITE) ;
        dsgW1.add(q1) ;
        dsgW1.commit() ;
        dsgW1.end() ;

        DatasetGraphTxn dsgW2 = sConn.begin(ReadWrite.WRITE) ;
        dsgW2.add(q2) ;
        dsgW2.commit() ;
        dsgW2.end() ;

        DatasetGraphTxn dsgR2 = sConn.begin(ReadWrite.READ) ;
        assertTrue(dsgR2.contains(q1)) ;
        assertTrue(dsgR2.contains(q2)) ;
        dsgR2.end() ;
       
        DatasetGraph dsg = sConn.getBaseDataset() ;
        assertTrue(dsg.contains(q1)) ;
        assertTrue(dsg.contains(q2)) ;
    }
View Full Code Here

    }
   
    @Test public void trans_06()
    {
        // READ(start)-READ(finish)-WRITE(start)-WRITE(commit)-check
        StoreConnection sConn = getStoreConnection() ;
       
        DatasetGraphTxn dsgR2 = sConn.begin(ReadWrite.READ) ;
        assertFalse(dsgR2.contains(q1)) ;
        assertFalse(dsgR2.contains(q2)) ;
        dsgR2.end() ;
       
        DatasetGraphTxn dsgW1 = sConn.begin(ReadWrite.WRITE) ;
        dsgW1.add(q1) ;
        dsgW1.add(q2) ;
        dsgW1.commit() ;
        dsgW1.end() ;

        sConn.forceRecoverFromJournal() ;
        DatasetGraph dsg = sConn.getBaseDataset() ;
        assertTrue(dsg.contains(q1)) ;
        assertTrue(dsg.contains(q2)) ;
    }
View Full Code Here

   
    @Test public void trans_readBlock_01()
    {
        // READ(start)-WRITE(commit)-READ(finish)-check
        StoreConnection sConn = getStoreConnection() ;
        DatasetGraphTxn dsgR1 = sConn.begin(ReadWrite.READ) ;
       
        DatasetGraphTxn dsgW = sConn.begin(ReadWrite.WRITE) ;
       
        dsgW.add(q) ;
        dsgW.commit() ;
        dsgW.end() ;
       
        assertFalse(dsgR1.contains(q)) ;
        dsgR1.end() ;

        //**** Not hitting the queue ****
        // Order of tweaking counters?
        // also writer and counters?
       
        DatasetGraphTxn dsgR2 = sConn.begin(ReadWrite.READ) ;
        assertTrue(dsgR2.contains(q)) ;
        dsgR2.end() ;
       
        DatasetGraph dsg = sConn.getBaseDataset() ;
        assertTrue(dsg.contains(q)) ;
    }
View Full Code Here

        }
    }
   
    //@Test
    public void test() {
        final StoreConnection storeConnection =
                StoreConnection.make(Location.mem());

        //ExecutorService executor = Executors.newCachedThreadPool()  ;     // Not seen blocking.
        // 4 blocks maybe 1 in 4 times
        // 8 blocks (quad core) 2 in 3 times.
        ExecutorService executor = Executors.newFixedThreadPool(8) ;

        final AtomicInteger nbQuadruplesAdded = new AtomicInteger();

        final CountDownLatch doneSignal =
                new CountDownLatch(CONCURRENT_RANDOM_OPERATIONS);

        for (int i = 0; i < CONCURRENT_RANDOM_OPERATIONS; i++) {
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        if (numberGenerator.nextInt(2) == 0) {
                            DatasetGraphTxn txnGraph =
                                    storeConnection.begin(ReadWrite.WRITE);
                            txnGraph.add(new Quad(
                                    Node.createURI("http://openjena.org/"
                                            + numberGenerator.nextInt()),
                                    Node.createURI("http://openjena.org/"
                                            + numberGenerator.nextInt()),
                                    Node.createURI("http://openjena.org/"
                                            + numberGenerator.nextInt()),
                                    Node.createURI("http://openjena.org/"
                                            + numberGenerator.nextInt())));
                            txnGraph.commit();
                            txnGraph.end();
                            nbQuadruplesAdded.incrementAndGet();
                        } else {
                            DatasetGraphTxn txnGraph =
                                    storeConnection.begin(ReadWrite.READ);
                            txnGraph.find(Node.ANY, Node.ANY, Node.ANY, Node.ANY);
                            //Iterator<Quad> iter = txnGraph.find(Node.ANY, Node.ANY, Node.ANY, Node.ANY);
                            //Iter.count(iter) ; // Consume
                            txnGraph.end();
                        }
                    } finally {
                        doneSignal.countDown();
                    }
                }
            });
        }

        // shutdown is orderly so sync'ing up before the shutdown is nice but not needed.
        try {
            doneSignal.await();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        } finally {
            executor.shutdown();
        }

        DatasetGraphTxn txnGraph =
                storeConnection.begin(ReadWrite.READ);
        Iterator<Quad> result = txnGraph.find(
                Node.ANY, Node.ANY, Node.ANY, Node.ANY);
       
        long count = 0;
        while (result.hasNext()) {
            result.next();
            count++;
        }
       
        txnGraph.end();
       
        StoreConnection.release(storeConnection.getLocation());

        //System.out.println() ;
        System.out.println("FINISHED") ;
       
//        // This is unsafe - the quad adds may generate duplicates (ity's unlikly 4 random number reoccur but it's possible).
View Full Code Here

    private StoreConnection sConn ;
    private static Random random = new Random(System.currentTimeMillis()) ;

    protected synchronized StoreConnection getStoreConnection()
    {
        StoreConnection sConn = StoreConnection.make(LOCATIONS.get(random.nextInt(NUM_DATASETS))) ;
        //sConn.getTransMgr().recording(true) ;
        return sConn ;
    }
View Full Code Here

    public T_TransSystemMultiDatasets() {}
       
    //@Test
    public void manyRead()
    {
        final StoreConnection sConn = getStoreConnection() ;
        Callable<?> proc = new ReaderTx(this, 50, 200;        // Number of repeats, max pause
           
        for ( int i = 0 ; i < 5 ; i++ )
            execService.submit(proc) ;
        try
View Full Code Here

TOP

Related Classes of com.hp.hpl.jena.tdb.StoreConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.