Package org.akubraproject

Examples of org.akubraproject.BlobStoreConnection


  /**
   * Tests that the connection cache works as expected.
   */
  @Test
  public void testGetConnection() throws IOException {
    BlobStoreConnection con1 = con.getConnection(store1, null);
    BlobStoreConnection con2 = con.getConnection(store2, null);
    assertEquals(2, con.getCons().size());
    assertEquals(con.getCons().get(store1.getId()), con1);
    assertEquals(con.getCons().get(store2.getId()), con2);
    assertEquals(con1, con.getConnection(store1, null));
    assertEquals(con2, con.getConnection(store2, null));
View Full Code Here


    assertFalse(rs.next(), "unexpected entries in deleted-list table;");
  }

  private void doInTxn(ConAction a, boolean commit) throws Exception {
    tm.begin();
    BlobStoreConnection con = store.openConnection(tm.getTransaction(), null);

    try {
      a.run(con);

      if (commit)
        tm.commit();
      else
        tm.rollback();
    } finally {
      if (tm.getTransaction() != null) {
        try {
          tm.rollback();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }

      con.close();
    }
  }
View Full Code Here

      return null;

    if (cons == null)
      throw new IllegalStateException("Connection closed.");

    BlobStoreConnection con = cons.get(store.getId());

    if (con == null) {
      con = store.openConnection(txn, hints);
      cons.put(store.getId(), con);
    }
View Full Code Here

    this.mapper = mapper;
  }

  @Override
  public BlobStoreConnection openConnection(Transaction tx, Map<String, String> hints) throws IOException {
    BlobStoreConnection connection = store.openConnection(tx, hints);
    return new IdMappingBlobStoreConnection(this, connection, mapper);
  }
View Full Code Here

    return fetchBlob(request.getEmail(), request.generateFilename());
  }
 
  @Override
  public Blob fetchBlob(String email, String filename) {
    BlobStoreConnection connection = openConnection(blobStore);
    return getBlob(connection, email, filename);
  }
View Full Code Here

  /**
   * Managed Streams should be tracked when open and closed when connection is closed.
   */
  @Test(dependsOnGroups = { "init" })
  public void testTrackedConnectionCloses() throws Exception {
    BlobStoreConnection con1 = new MockConnection(manager);
    BlobStoreConnection con2 = new MockConnection(manager);

    manager.manageInputStream(con1, new ByteArrayInputStream(new byte[0]));
    manager.manageOutputStream(con1, new ByteArrayOutputStream());
    assertEquals(manager.getOpenInputStreamCount(), 1);
    assertEquals(manager.getOpenOutputStreamCount(), 1);

    manager.manageInputStream(con2, new ByteArrayInputStream(new byte[0]));
    manager.manageOutputStream(con2, new ByteArrayOutputStream());
    assertEquals(manager.getOpenInputStreamCount(), 2);
    assertEquals(manager.getOpenOutputStreamCount(), 2);

    con1.close();
    assertEquals(manager.getOpenInputStreamCount(), 1);
    assertEquals(manager.getOpenOutputStreamCount(), 1);

    con2.close();
    assertEquals(manager.getOpenInputStreamCount(), 0);
    assertEquals(manager.getOpenOutputStreamCount(), 0);
  }
View Full Code Here

      con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);

      tx.enlistResource(xaCon.getXAResource());

      BlobStoreConnection bsc =
          new TransactionalConnection(this, wrappedStore, xaCon, con, tx, hints, version);

      if (logger.isDebugEnabled())
        logger.debug("Opened connection, read-version=" + version);
View Full Code Here

          findOld.setLong(1, minVers);
          rs = findOld.executeQuery();
          int cntB = 0;

          try {
            BlobStoreConnection bsc = wrappedStore.openConnection(null, null);
            try {
              while (rs.next()) {
                cntB++;
                String storeId = rs.getString(1);
                if (logger.isTraceEnabled())
                  logger.trace("Purging deleted blob '" + storeId + "'");

                try {
                  bsc.getBlob(URI.create(storeId), null).delete();
                } catch (IOException ioe) {
                  logger.warn("Error purging blob '" + storeId + "'", ioe);
                }
              }
            } finally {
              bsc.close();
            }
          } catch (IOException ioe) {
            logger.warn("Error opening connection to underlying store to purge old versions", ioe);
          } finally {
            try {
              rs.close();
            } finally {
              findOld.close();
            }
          }

          // purge processed entries from the delete table
          String sql = "SELECT version FROM " + DEL_TABLE +
                       " -- DERBY-PROPERTIES index=DELETED_LIST_VIDX \n WHERE version < ?";
          PreparedStatement purge =
              con.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
          purge.setLong(1, minVers);
          rs = purge.executeQuery();
          int cntD = 0;

          try {
            while (rs.next()) {
              cntD++;
              rs.deleteRow();
            }
          } finally {
            try {
              rs.close();
            } finally {
              purge.close();
            }
          }

          // debug log the stats
          try {
            int cntL = 0;
            if (logger.isTraceEnabled()) {
              BlobStoreConnection bsc = wrappedStore.openConnection(null, null);
              for (Iterator<URI> iter = bsc.listBlobIds(null); iter.hasNext(); iter.next())
                cntL++;
              bsc.close();
            }

            if (logger.isDebugEnabled())
              logger.debug("purged: " + cntM + " mappings, " + cntB + " blobs, " + cntD +
                           " deletes" + (logger.isTraceEnabled() ? "; " + cntL + " blobs left" : ""));
View Full Code Here

   * Request to open a connection without a transaction.
   */
  @Test(groups={ "store" }, dependsOnGroups={ "init" })
  public void testOpenConnectionNoTransaction() {
    try {
      BlobStoreConnection con = store.openConnection(null, null);
      if (isTransactional)
        fail("Did not get expected IOException initializing store without a transaction");

      assertNotNull(con, "Null connection returned from openConnection(null)");
      assertSame(con.getBlobStore(), store);
    } catch (IOException ioe) {
      if (!isTransactional)
        fail("Got unexpected IOException initializing store without a transaction", ioe);
    }
  }
View Full Code Here

   * Request to open a connection with a transaction.
   */
  @Test(groups={ "store" }, dependsOnGroups={ "init" })
  public void testOpenConnectionWithTransaction() throws Exception {
    tm.begin();
    BlobStoreConnection con = null;

    try {
      con = store.openConnection(tm.getTransaction(), null);
      if (!isTransactional)
        fail("Did not get expected UnsupportedOperationException while initializing store with " +
             "a transaction");

      assertNotNull(con, "Null connection returned from openConnection(txn)");
      assertSame(con.getBlobStore(), store);
    } catch (UnsupportedOperationException uoe) {
      if (isTransactional)
        fail("Got unexpected UnsupportedOperationException initializing store with a transaction",
             uoe);
    } finally {
      tm.rollback();
      if (con != null)
        con.close();
    }
  }
View Full Code Here

TOP

Related Classes of org.akubraproject.BlobStoreConnection

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.