Package org.sonatype.nexus.blobstore.api

Examples of org.sonatype.nexus.blobstore.api.BlobId


      TestWorker r = new TestWorker(testWorkers.size(), startingGun, failureHasOccurred, numberOfIterations,
          new TestTask()
          {
            @Override
            public void run() throws Exception {
              final BlobId blobId = blobIdsInTheStore.peek();

              log("Attempting to read " + blobId);

              if (blobId == null) {
                return;
              }

              final Blob blob = underTest.get(blobId);
              if (blob == null) {
                log("Attempted to obtain blob, but it was deleted:" + blobId);
                return;
              }

              try (InputStream inputStream = blob.getInputStream()) {
                readContentAndValidateMetrics(blobId, inputStream, blob.getMetrics());
              }
              catch (BlobStoreException e) {
                // This is normal operation if another thread deletes your blob after you obtain a Blob reference
                log("Concurrent deletion suspected while calling blob.getInputStream().", e);
              }
            }
          }
      );
      testWorkers.add(r);
    }

    for (int i = 0; i < numberOfDeleters; i++) {
      testWorkers
          .add(new TestWorker(testWorkers.size(), startingGun, failureHasOccurred, numberOfIterations, new TestTask()
          {
            @Override
            public void run() throws Exception {
              final BlobId blobId = blobIdsInTheStore.poll();
              if (blobId == null) {
                log("deleter: null blob id");
                return;
              }
              underTest.delete(blobId);
            }
          }));
    }

    // Shufflers pull blob IDs off the front of the queue and stick them on the back, to make the blobID queue a bit less orderly
    for (int i = 0; i < numberOfShufflers; i++) {
      testWorkers.add(
          new TestWorker(testWorkers.size(), startingGun, failureHasOccurred, numberOfIterations, new TestTask()
          {
            @Override
            public void run() throws Exception {
              final BlobId blobId = blobIdsInTheStore.poll();
              if (blobId != null) {
                blobIdsInTheStore.add(blobId);
              }
            }
          }));
View Full Code Here


  }

  @Test
  public void stateTracking() throws Exception {
    BlobMetadata md = new BlobMetadata(BlobState.CREATING, ImmutableMap.of("foo", "bar"));
    BlobId id = underTest.add(md);
    log("Added: {} -> {}", id, md);

    // states should only contain CREATING
    assertThat(findWithState(BlobState.CREATING), contains(id));
    assertThat(findWithState(BlobState.ALIVE), emptyIterable());
View Full Code Here

    BlobMetadata md = new BlobMetadata(BlobState.CREATING, ImmutableMap.of("foo", "bar"));
    log(md);

    // add a record
    log("add");
    BlobId id = underTest.add(md);
    log(id);

    dumpStates();

    // update a record
View Full Code Here

  }

  private Blob getLocalBlob(ODocument assetDocument) {
    Map<String, String> blobRefs = assetDocument.field(P_BLOB_REFS);
    checkState(blobRefs.containsKey(localBlobStoreId), "Local blobRef does not exist for that asset");
    BlobId blobId = new BlobId(blobRefs.get(localBlobStoreId));
    Blob blob = blobStore.get(new BlobId(blobRefs.get(localBlobStoreId)));
    checkState(blob != null, "Blob not found in local store: %", blobId.asUniqueString());
    return blob;
  }
View Full Code Here

  /**
   * Generate a new blob identifier.
   */
  private BlobId newId(final DB db) {
    long id = idSequence(db).incrementAndGet();
    return new BlobId(String.format("%016x", id));
  }
View Full Code Here

    return database.execute(new Fun.Function1<BlobId, DB>()
    {
      @Override
      public BlobId run(final DB db) {
        BlobId id = newId(db);
        log.trace("Add: {}={}", id, record);

        MetadataRecord prev = entries(db).put(id, record);
        checkState(prev == null, "Duplicate blob-id: %s", id);
View Full Code Here

    checkNotNull(headers);

    checkArgument(headers.containsKey(BLOB_NAME_HEADER), "Missing header: %s", BLOB_NAME_HEADER);
    checkArgument(headers.containsKey(CREATED_BY_HEADER), "Missing header: %s", CREATED_BY_HEADER);

    BlobId blobId = null;

    try {
      // If the storing of bytes fails, we record a reminder to clean up afterwards
      final BlobMetadata metadata = new BlobMetadata(BlobState.CREATING, headers);
      blobId = metadataStore.add(metadata);
View Full Code Here

    underTest.create(inputStream, headers);
  }

  @Test
  public void successfulCreation() throws Exception {
    final BlobId fakeId = new BlobId("testId");
    final long contentSize = 200L;
    final String fakeSHA1 = "3757y5abc234cfgg";
    final InputStream inputStream = mock(InputStream.class);
    final ImmutableMap<String, String> headers = ImmutableMap.of(
        BlobStore.BLOB_NAME_HEADER, "my blob",
View Full Code Here

        metrics.getCreationTime().isAfter(new DateTime().minusSeconds(2)));
  }

  @Test
  public void getExistingBlob() throws Exception {
    final BlobId fakeId = new BlobId("fakeId");
    final BlobMetadata metadata = mock(BlobMetadata.class);
    when(metadataStore.get(fakeId)).thenReturn(metadata);
    when(metadata.isAlive()).thenReturn(true);
    when(metadata.getMetrics()).thenReturn(mock(BlobMetrics.class));
View Full Code Here

    assertThat(blob.getId(), is(equalTo(fakeId)));
  }

  @Test
  public void deletingMarksAsDeleted() {
    final BlobId fakeId = new BlobId("fakeId");
    final BlobMetadata metadata = mock(BlobMetadata.class);
    when(metadataStore.get(fakeId)).thenReturn(metadata);

    // The blob isn't already deleted
    when(metadata.isAlive()).thenReturn(true);
View Full Code Here

TOP

Related Classes of org.sonatype.nexus.blobstore.api.BlobId

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.