use of org.commonjava.maven.galley.model.ConcreteResource in project galley by Commonjava.
the class RoutingCacheProviderWrapperTest method prepare.
@Before
public void prepare() throws Exception {
final File cacheDir = temp.newFolder();
partylineFac = new PartyLineCacheProviderFactory(cacheDir);
DefaultCacheManager cacheManager = new DefaultCacheManager();
SimpleCacheInstance<String, String> cacheInstance = new SimpleCacheInstance<>("test", cacheManager.getCache("simpleNfsCache"));
SimpleCacheInstance<String, ConcreteResource> testLocalFileCacheInstance = new SimpleCacheInstance<>("testLocalFileCache", cacheManager.getCache("simpleLocalFileCache"));
fastLocalFac = new FastLocalCacheProviderFactory(cacheDir, temp.newFolder(), cacheInstance, testLocalFileCacheInstance, Executors.newFixedThreadPool(5));
}
use of org.commonjava.maven.galley.model.ConcreteResource in project galley by Commonjava.
the class TransferManagerImpl method retrieveFirst.
@Override
public Transfer retrieveFirst(final VirtualResource virt, final EventMetadata eventMetadata) throws TransferException {
Transfer target;
TransferException lastError = null;
int tries = 0;
for (final ConcreteResource res : virt) {
tries++;
if (res == null) {
continue;
}
try {
target = retrieve(res, true, eventMetadata);
lastError = null;
if (target != null && target.exists()) {
return target;
}
} catch (final TransferException e) {
logger.warn("Failed to retrieve: {}. {} more tries. (Reason: {})", res, (virt.toConcreteResources().size() - tries), e.getMessage());
lastError = e;
}
}
if (lastError != null) {
throw lastError;
}
fileEventManager.fire(new FileNotFoundEvent(virt, eventMetadata));
return null;
}
use of org.commonjava.maven.galley.model.ConcreteResource in project galley by Commonjava.
the class TransferManagerImpl method doBatch.
@SuppressWarnings("RedundantThrows")
private <T extends TransferBatch> T doBatch(final Set<Resource> resources, final T batch, final boolean suppressFailures, final EventMetadata eventMetadata) throws TransferException {
logger.info("Attempting to batch-retrieve {} resources:\n {}", resources.size(), new JoinString("\n ", resources));
final Set<BatchRetriever> retrievers = new HashSet<>(resources.size());
for (final Resource resource : resources) {
retrievers.add(new BatchRetriever(this, resource, suppressFailures, eventMetadata));
}
final Map<ConcreteResource, TransferException> errors = new HashMap<>();
final Map<ConcreteResource, Transfer> transfers = new HashMap<>();
do {
for (final BatchRetriever retriever : retrievers) {
batchExecutor.submit(retriever);
}
int count = retrievers.size();
for (int i = 0; i < count; i++) {
try {
Future<BatchRetriever> pending = batchExecutor.take();
BatchRetriever retriever = pending.get();
final ConcreteResource resource = retriever.getLastTry();
final TransferException error = retriever.getError();
if (error != null) {
logger.warn("ERROR: {}...{}", error, resource, error.getMessage());
retrievers.remove(retriever);
if (!(error instanceof TransferLocationException)) {
errors.put(resource, error);
}
continue;
}
final Transfer transfer = retriever.getTransfer();
if (transfer != null && transfer.exists()) {
transfers.put(resource, transfer);
retrievers.remove(retriever);
logger.debug("Completed: {}", resource);
continue;
}
if (!retriever.hasMoreTries()) {
logger.debug("Not completed, but out of tries: {}", resource);
retrievers.remove(retriever);
}
} catch (final InterruptedException e) {
logger.error(String.format("Failed to wait for batch retrieval attempts to complete: %s", e.getMessage()), e);
break;
} catch (ExecutionException e) {
logger.error(String.format("Failed to retrieve next completed retrieval: %s", e.getMessage()), e);
}
}
} while (!retrievers.isEmpty());
batch.setErrors(errors);
batch.setTransfers(transfers);
return batch;
}
use of org.commonjava.maven.galley.model.ConcreteResource in project galley by Commonjava.
the class PartyLineCacheProviderConcurrentIOTest method testBigFileWrite.
@Test
public void testBigFileWrite() throws Exception {
StringBuilder builder = new StringBuilder();
int loop = 1024 * 1024 * 10;
for (int i = 0; i < loop; i++) {
builder.append(content);
}
final String bigContent = builder.toString();
System.out.println(String.format("the content size is: %dm", bigContent.length() / 1024 / 1024));
final ConcreteResource resource = createTestResource("file_read_write_bigfile.txt");
new WriteTask(provider, bigContent, resource, null).run();
assertThat(provider.exists(resource), equalTo(true));
assertThat(TestIOUtils.readFromStream(new FileInputStream(provider.getDetachedFile(resource))), equalTo(bigContent));
}
use of org.commonjava.maven.galley.model.ConcreteResource in project galley by Commonjava.
the class CacheProviderTCK method writeAndListDirectory.
@Test
public void writeAndListDirectory() throws Exception {
final String content = "This is a test";
final Location loc = new SimpleLocation("http://foo.com");
final String dir = "/path/to/my/";
final String fname = dir + "file.txt";
final CacheProvider provider = getCacheProvider();
final OutputStream out = provider.openOutputStream(new ConcreteResource(loc, fname));
out.write(content.getBytes("UTF-8"));
out.flush();
out.close();
// NOTE: This is NOT as tightly specified as I would like.
// We keep the listing assertions loose (greater-than instead of equals,
// contains instead of exact positional assertion) because the Infinispan
// live testing has these spurious foo.txt.#0 files cropping up.
//
// I have no idea what they are, but I'm sick of fighting JBoss bugs for now.
final Set<String> listing = new HashSet<String>(Arrays.asList(provider.list(new ConcreteResource(loc, dir))));
System.out.printf("\n\nFile listing is:\n\n %s\n\n\n", join(listing, "\n "));
assertThat(listing.size() > 0, equalTo(true));
assertThat(listing.contains("file.txt"), equalTo(true));
}
Aggregations