Search in sources :

Example 1 with IArtifactSink

use of org.eclipse.tycho.repository.p2base.artifact.provider.streaming.IArtifactSink in project tycho by eclipse.

the class LocalArtifactRepositoryP2APITest method testWriteArtifact.

@Test
public void testWriteArtifact() throws Exception {
    IArtifactSink addSink = subject.newAddingArtifactSink(NEW_KEY);
    addSink.beginWrite().write(new byte[33]);
    addSink.commitWrite();
    assertTrue(subject.contains(NEW_KEY));
    assertTrue(subject.contains(localCanonicalDescriptorFor(NEW_KEY)));
    assertThat(readSizeOfArtifact(NEW_KEY), is(33));
}
Also used : IArtifactSink(org.eclipse.tycho.repository.p2base.artifact.provider.streaming.IArtifactSink) Test(org.junit.Test)

Example 2 with IArtifactSink

use of org.eclipse.tycho.repository.p2base.artifact.provider.streaming.IArtifactSink in project tycho by eclipse.

the class LocalArtifactRepositoryP2APITest method testGetArtifactToBrokenSink.

@Test(expected = ArtifactSinkException.class)
public void testGetArtifactToBrokenSink() throws Exception {
    IArtifactSink brokenSink = new IArtifactSink() {

        @Override
        public IArtifactKey getArtifactToBeWritten() {
            return ARTIFACT_A_KEY;
        }

        @Override
        public boolean canBeginWrite() {
            return true;
        }

        @Override
        public OutputStream beginWrite() {
            return testOutputStream;
        }

        @Override
        public void commitWrite() throws ArtifactSinkException {
            throw new ArtifactSinkException("simulated error on commit");
        }

        @Override
        public void abortWrite() {
        }
    };
    subject.getArtifact(brokenSink, null);
}
Also used : ArtifactSinkException(org.eclipse.tycho.repository.p2base.artifact.provider.streaming.ArtifactSinkException) IArtifactSink(org.eclipse.tycho.repository.p2base.artifact.provider.streaming.IArtifactSink) Test(org.junit.Test)

Example 3 with IArtifactSink

use of org.eclipse.tycho.repository.p2base.artifact.provider.streaming.IArtifactSink in project tycho by eclipse.

the class MirroringArtifactProvider method createCanonicalArtifactFromLocalPackedArtifact.

private void createCanonicalArtifactFromLocalPackedArtifact(IArtifactKey key) throws ProvisionException, ArtifactSinkException {
    logger.info("Unpacking " + key.getId() + "_" + key.getVersion() + "...");
    // TODO 397355 ignore ProvisionException.ARTIFACT_EXISTS
    IArtifactSink sink = localArtifactRepository.newAddingArtifactSink(key);
    localArtifactRepository.getArtifact(sink, monitor);
}
Also used : IArtifactSink(org.eclipse.tycho.repository.p2base.artifact.provider.streaming.IArtifactSink)

Example 4 with IArtifactSink

use of org.eclipse.tycho.repository.p2base.artifact.provider.streaming.IArtifactSink in project tycho by eclipse.

the class ModuleArtifactRepositoryTest method testWriteToRepository.

@Test
public void testWriteToRepository() throws Exception {
    subject = ModuleArtifactRepository.createInstance(null, tempManager.newFolder("targetDir"));
    // TODO this should not be necessary
    subject.setGAV("", "", "");
    IArtifactSink sink = subject.newAddingArtifactSink(BINARY_ARTIFACT_KEY, new WriteSessionStub());
    writeAndClose(sink.beginWrite(), BINARY_ARTIFACT_SIZE);
    sink.commitWrite();
    assertThat(artifactSizeOf(BINARY_ARTIFACT_KEY, subject), is(BINARY_ARTIFACT_SIZE));
}
Also used : IArtifactSink(org.eclipse.tycho.repository.p2base.artifact.provider.streaming.IArtifactSink) Test(org.junit.Test)

Example 5 with IArtifactSink

use of org.eclipse.tycho.repository.p2base.artifact.provider.streaming.IArtifactSink in project tycho by eclipse.

the class CompositeArtifactProviderTestBase method testGetArtifactWithNonRestartableSink.

@Test
public void testGetArtifactWithNonRestartableSink() throws Exception {
    subject = createCompositeArtifactProvider(REPO_BUNDLE_A_CORRUPT, REPO_BUNDLE_A);
    IArtifactSink nonRestartableSink = ArtifactSinkFactory.writeToStream(BUNDLE_A_KEY, testOutputStream);
    status = subject.getArtifact(nonRestartableSink, null);
    // first read attempt fails -> operation fails
    assertThat(status, is(errorStatus()));
    // original message from p2 as top-level status
    assertThat(status.getMessage(), containsString("An error occurred while transferring artifact"));
}
Also used : IArtifactSink(org.eclipse.tycho.repository.p2base.artifact.provider.streaming.IArtifactSink) Test(org.junit.Test)

Aggregations

IArtifactSink (org.eclipse.tycho.repository.p2base.artifact.provider.streaming.IArtifactSink)8 Test (org.junit.Test)7 ProvisionException (org.eclipse.equinox.p2.core.ProvisionException)1 ArtifactSinkException (org.eclipse.tycho.repository.p2base.artifact.provider.streaming.ArtifactSinkException)1