Package com.asakusafw.runtime.util.cache

Examples of com.asakusafw.runtime.util.cache.HadoopFileCacheRepository


            Path repositoryPath = computeRepositoryPath();
            File temporary = computeTemporaryDirectory();
            int threads = Math.max(configuration.getInt(KEY_MAX_THREADS, DEFAULT_MAX_THREADS), MINIMUM_MAX_THREADS);
            int retryCount = configuration.getInt(KEY_CACHE_RETRY_COUNT, DEFAULT_CACHE_RETRY_COUNT);
            long retryInterval = configuration.getLong(KEY_CACHE_RETRY_INTERVAL, DEFAULT_CACHE_RETRY_INTERVAL);
            FileCacheRepository unit = new HadoopFileCacheRepository(
                    configuration,
                    repositoryPath,
                    new LocalFileLockProvider<Path>(new File(temporary, PATH_LOCK_DIRECTORY)),
                    new ConstantRetryStrategy(retryCount, retryInterval));
            ExecutorService executor = Executors.newFixedThreadPool(threads, DAEMON_THREAD_FACTORY);
View Full Code Here


    public void simple() throws Exception {
        File cacheRepo = folder.newFolder();
        Configuration configuration = new ConfigurationProvider().newInstance();
        LockProvider<Path> locks = new LocalFileLockProvider<Path>(folder.newFolder());
        RetryStrategy retrier = new ConstantRetryStrategy();
        HadoopFileCacheRepository cache = new HadoopFileCacheRepository(configuration, path(cacheRepo), locks, retrier);

        File source = put(folder.newFile(), "Hello, world!");
        Path resolved = cache.resolve(path(source));

        assertThat(get(file(resolved)), is("Hello, world!"));
        assertThat(resolved, is(not(path(source))));
        assertThat(containsFile(cacheRepo, file(resolved)), is(true));
    }
View Full Code Here

    public void update() throws Exception {
        File cacheRepo = folder.newFolder();
        Configuration configuration = new ConfigurationProvider().newInstance();
        LockProvider<Path> locks = new LocalFileLockProvider<Path>(folder.newFolder());
        RetryStrategy retrier = new ConstantRetryStrategy();
        HadoopFileCacheRepository cache = new HadoopFileCacheRepository(configuration, path(cacheRepo), locks, retrier);

        File source = put(folder.newFile(), "Hello, world!");
        Path first = cache.resolve(path(source));

        put(source, "UPDATED");
        Path retry = cache.resolve(path(source));

        assertThat(retry, is(first));
        assertThat(get(file(retry)), is("UPDATED"));
    }
View Full Code Here

    public void cached() throws Exception {
        File cacheRepo = folder.newFolder();
        Configuration configuration = new ConfigurationProvider().newInstance();
        LockProvider<Path> locks = new LocalFileLockProvider<Path>(folder.newFolder());
        RetryStrategy retrier = new ConstantRetryStrategy();
        HadoopFileCacheRepository cache = new HadoopFileCacheRepository(configuration, path(cacheRepo), locks, retrier);

        File source = put(folder.newFile(), "Hello, world!");
        Path first = cache.resolve(path(source));
        long timestamp = file(first).lastModified();
        Assume.assumeThat(timestamp, is(greaterThan(0L)));

        for (int i = 0; i < 10; i++) {
            if (System.currentTimeMillis() != timestamp) {
                break;
            }
            Thread.sleep(10);
        }
        Assume.assumeThat(System.currentTimeMillis(), is(not(timestamp)));

        // may not changed
        Path retry = cache.resolve(path(source));
        assertThat(file(retry).lastModified(), is(timestamp));
    }
View Full Code Here

        final Path path = path(source);
        File cacheRepo = folder.newFolder();
        Configuration configuration = new ConfigurationProvider().newInstance();
        LockProvider<Path> locks = new LocalFileLockProvider<Path>(folder.newFolder());
        RetryStrategy retrier = new ConstantRetryStrategy(30, 100, 200);
        final FileCacheRepository cache = new HadoopFileCacheRepository(configuration, path(cacheRepo), locks, retrier);

        List<Future<Path>> futures = new ArrayList<Future<Path>>();
        int count = 10;
        final CountDownLatch latch = new CountDownLatch(count);
        ExecutorService executor = Executors.newFixedThreadPool(count);
        try {
            for (int i = 0; i < count; i++) {
                final String label = String.format("thread-%d", i);
                futures.add(executor.submit(new Callable<Path>() {
                    @Override
                    public Path call() throws Exception {
                        LOG.info("Wait: resolve @" + label);
                        latch.countDown();
                        if (latch.await(5, TimeUnit.SECONDS) == false) {
                            throw new TimeoutException();
                        }
                        LOG.info("Start: resolve @" + label);
                        Path result = cache.resolve(path);

                        LOG.info("Finish: resolve @" + label);
                        return result;
                    }
                }));
View Full Code Here

TOP

Related Classes of com.asakusafw.runtime.util.cache.HadoopFileCacheRepository

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.