Skip to content

Commit

Permalink
Merge branch 'release/1.2.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
overheadhunter committed Dec 9, 2020
2 parents d3ee7dc + efeb19a commit e66c297
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 92 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Build

on:
[push]

jobs:
build:
name: Build and Test
runs-on: ubuntu-latest
#This check is case insensitive
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')"
outputs:
# Get from step "setversion"
artifact-version: ${{ steps.setversion.outputs.version }}
env:
BUILD_VERSION: SNAPSHOT
# Name of the project; used in multiple steps (e.g. for upload)
PROJECT_NAME: fuse-nio-adapter
steps:
# Foreign Action: Checkout the current commit
- uses: actions/checkout@v2
# Foreign Action: Setup Java Runtime Environment
- uses: actions/setup-java@v1
with:
java-version: 11
server-id: bintray-jcenter
server-username: BINTRAY_USERNAME # Defined in step "deploytojcenter"
server-password: BINTRAY_API_KEY # See above
- uses: actions/cache@v1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Ensure to use tagged version
id: taggedVersion
run: mvn versions:set --file ./pom.xml -DnewVersion=${GITHUB_REF##*/}
if: startsWith(github.ref, 'refs/tags/') # Run if ref is tagged (e.g. "v.1.4")
- name: Export the project version to the job environment and fix it as an ouput of this step
id: setVersion # Output used above (outputs.artifact-version)
run: |
v=$(mvn help:evaluate "-Dexpression=project.version" -q -DforceStdout)
echo "BUILD_VERSION=${v}" >> $GITHUB_ENV
echo "::set-output name=version::${v}"
- name: Build and Test
id: buildAndTest
run: mvn -B clean install jacoco:report -Pcoverage,dependency-check
- name: Upload code coverage report
id: codacyCoverageReporter
run: bash <(curl -Ls https://coverage.codacy.com/get.sh)
env:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
continue-on-error: true
- name: Upload snapshot artifact ${{ env.PROJECT_NAME }}-${{ env.BUILD_VERSION }}.jar
id: uploadSnapshot
uses: actions/upload-artifact@v2
with:
name: ${{ env.PROJECT_NAME }}-${{ env.BUILD_VERSION }}.jar
path: target/${{ env.PROJECT_NAME }}-*.jar
- name: Deploy to jcenter
id: deployToJcenter
run: mvn -B deploy -Prelease -DskipTests
if: startsWith(github.ref, 'refs/tags/') # Run if ref is tagged (e.g. "v.1.4")
env:
BINTRAY_USERNAME: cryptobot
BINTRAY_API_KEY: ${{ secrets.BINTRAY_API_KEY }}
28 changes: 0 additions & 28 deletions .travis.yml

This file was deleted.

9 changes: 5 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.cryptomator</groupId>
<artifactId>fuse-nio-adapter</artifactId>
<version>1.2.5</version>
<version>1.2.6</version>
<name>FUSE-NIO-Adapter</name>
<description>Access resources at a given NIO path via FUSE.</description>
<url>https://github.com/cryptomator/fuse-nio-adapter</url>
Expand All @@ -15,9 +15,11 @@
</scm>

<properties>
<maven.compiler.release>11</maven.compiler.release>

<jnrfuse.version>0.5.4</jnrfuse.version>
<dagger.version>2.27</dagger.version>
<guava.version>29.0-jre</guava.version>
<guava.version>30.0-jre</guava.version>
<slf4j.version>1.7.30</slf4j.version>

<junit.jupiter.version>5.6.2</junit.jupiter.version>
Expand Down Expand Up @@ -125,7 +127,6 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>9</release>
<showWarnings>true</showWarnings>
<annotationProcessorPaths>
<path>
Expand All @@ -151,7 +152,7 @@
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>5.3.2</version>
<version>6.0.2</version>
<configuration>
<cveValidForHours>24</cveValidForHours>
<failBuildOnCVSS>0</failBuildOnCVSS>
Expand Down
21 changes: 9 additions & 12 deletions src/main/java/org/cryptomator/frontend/fuse/locks/LockManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.cryptomator.frontend.fuse.locks;

import com.google.common.base.Supplier;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
Expand Down Expand Up @@ -50,10 +51,10 @@ public class LockManager {
public LockManager() {
CacheBuilder<Object, Object> cacheBuilder = CacheBuilder.newBuilder().weakValues();
if (LOG.isDebugEnabled()) {
cacheBuilder.removalListener(this::onLockRemoval);
cacheBuilder.removalListener(this::removedReadWriteLock);
}
this.pathLocks = cacheBuilder.build(new LockLoader());
this.dataLocks = cacheBuilder.build(new LockLoader());
this.pathLocks = cacheBuilder.build(CacheLoader.from(this::createReadWriteLock));
this.dataLocks = cacheBuilder.build(CacheLoader.from(this::createReadWriteLock));
}

public PathLockBuilder createPathLock(String path) {
Expand All @@ -73,17 +74,13 @@ private PathLockBuilder createPathLock(List<String> pathComponents) {
return new PathLockBuilderImpl(pathComponents, Optional.ofNullable(parentLockBuilder), lock, dataLocks::getUnchecked);
}

private void onLockRemoval(RemovalNotification<String, ReentrantReadWriteLock> notification) {
LOG.trace("Deleting ReadWriteLock for {}", notification.getKey());
private ReadWriteLock createReadWriteLock(List<String> key) {
LOG.trace("Creating ReadWriteLock for {}", key);
return new ReentrantReadWriteLock();
}

private static class LockLoader extends CacheLoader<List<String>, ReadWriteLock> {

@Override
public ReadWriteLock load(List<String> key) {
LOG.trace("Creating ReadWriteLock for {}", key);
return new ReentrantReadWriteLock();
}
private void removedReadWriteLock(RemovalNotification<List<String>, ReentrantReadWriteLock> notification) {
LOG.trace("Deleting ReadWriteLock for {}", notification.getKey());
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.google.common.base.Preconditions;
import org.cryptomator.frontend.fuse.FuseNioAdapter;

import java.awt.*;
import java.awt.Desktop;
import java.io.IOException;
import java.nio.file.Path;

Expand All @@ -26,9 +26,9 @@ public Path getMountPoint() {

@Override
public void revealInFileManager() throws CommandFailedException {
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
try {
Desktop.getDesktop().browse(mountPoint.toUri());
Desktop.getDesktop().open(mountPoint.toFile());
} catch (IOException e) {
throw new CommandFailedException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public String[] defaultMountFlags() {
*/
@Override
public boolean isApplicable() {
return IS_MAC && Files.exists(Paths.get("/usr/local/lib/libosxfuse.2.dylib")) && installedVersionSupported();
return IS_MAC && Files.exists(Paths.get("/usr/local/lib/libosxfuse.2.dylib")); //
// && installedVersionSupported(); // FIXME: #52
}

public boolean installedVersionSupported() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package org.cryptomator.frontend.fuse.locks;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.Duration;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;


@Disabled //TODO: https://travis-ci.org/github/cryptomator/fuse-nio-adapter/builds/735702459
public class LockManagerTest {

static {
Expand Down Expand Up @@ -70,31 +71,26 @@ public void testMultipleReadLocks() {
LockManager lockManager = new LockManager();
int numThreads = 8;
ExecutorService threadPool = Executors.newFixedThreadPool(numThreads);
CyclicBarrier ready = new CyclicBarrier(8);
CountDownLatch done = new CountDownLatch(numThreads);
AtomicInteger counter = new AtomicInteger();
AtomicInteger maxCounter = new AtomicInteger();

for (int i = 0; i < numThreads; i++) {
int threadnum = i;
threadPool.submit(() -> {
try (PathLock lock = lockManager.createPathLock("/foo/bar/baz").forReading()) {
LOG.trace("ENTER thread {}", threadnum);
counter.incrementAndGet();
Thread.sleep(200);
maxCounter.set(Math.max(counter.get(), maxCounter.get()));
counter.decrementAndGet();
ready.await();
done.countDown();
LOG.trace("LEAVE thread {}", threadnum);
} catch (InterruptedException e) {
} catch (InterruptedException | BrokenBarrierException e) {
LOG.error("thread interrupted", e);
}
done.countDown();
});
}

Assertions.assertTimeoutPreemptively(Duration.ofSeconds(10), () -> { // deadlock protection
done.await();
});
Assertions.assertEquals(numThreads, maxCounter.get());
}

@Test
Expand All @@ -104,18 +100,20 @@ public void testMultipleWriteLocks() {
int numThreads = 8;
ExecutorService threadPool = Executors.newFixedThreadPool(numThreads);
CountDownLatch done = new CountDownLatch(numThreads);
AtomicInteger counter = new AtomicInteger();
AtomicInteger maxCounter = new AtomicInteger();
AtomicBoolean occupied = new AtomicBoolean(false);
AtomicBoolean success = new AtomicBoolean(true);

for (int i = 0; i < numThreads; i++) {
int threadnum = i;
threadPool.submit(() -> {
try (PathLock lock = lockManager.createPathLock("/foo/bar/baz").forWriting()) {
LOG.trace("ENTER thread {}", threadnum);
counter.incrementAndGet();
Thread.sleep(10);
maxCounter.set(Math.max(counter.get(), maxCounter.get()));
counter.decrementAndGet();
boolean wasFree = occupied.compareAndSet(false, true);
Thread.sleep(50); // give other threads the chance to reach this point
if (!wasFree) {
success.set(false);
}
occupied.set(false);
LOG.trace("LEAVE thread {}", threadnum);
} catch (InterruptedException e) {
LOG.error("thread interrupted", e);
Expand All @@ -127,7 +125,7 @@ public void testMultipleWriteLocks() {
Assertions.assertTimeoutPreemptively(Duration.ofSeconds(10), () -> { // deadlock protection
done.await();
});
Assertions.assertEquals(1, maxCounter.get());
Assertions.assertTrue(success.get());
}

@Test
Expand Down Expand Up @@ -203,58 +201,55 @@ class DataLockTests {

@Test
@DisplayName("read locks are shared")
public void testMultipleReadLocks() throws InterruptedException {
public void testMultipleReadLocks() {
LockManager lockManager = new LockManager();
int numThreads = 8;
ExecutorService threadPool = Executors.newFixedThreadPool(numThreads);
CyclicBarrier ready = new CyclicBarrier(8);
CountDownLatch done = new CountDownLatch(numThreads);
AtomicInteger counter = new AtomicInteger();
AtomicInteger maxCounter = new AtomicInteger();

for (int i = 0; i < numThreads; i++) {
int threadnum = i;
threadPool.submit(() -> {
try (PathLock pathLock = lockManager.createPathLock("/foo/bar/baz").forReading(); //
DataLock dataLock = pathLock.lockDataForReading()) {
LOG.trace("ENTER thread {}", threadnum);
counter.incrementAndGet();
Thread.sleep(50);
maxCounter.set(Math.max(counter.get(), maxCounter.get()));
counter.decrementAndGet();
ready.await();
done.countDown();
LOG.trace("LEAVE thread {}", threadnum);
} catch (InterruptedException e) {
} catch (InterruptedException | BrokenBarrierException e) {
LOG.error("thread interrupted", e);
}
done.countDown();
});
}

Assertions.assertTimeoutPreemptively(Duration.ofSeconds(10), () -> { // deadlock protection
done.await();
});
Assertions.assertEquals(numThreads, maxCounter.get());
}

@Test
@DisplayName("write locks are exclusive")
public void testMultipleWriteLocks() throws InterruptedException {
public void testMultipleWriteLocks() {
LockManager lockManager = new LockManager();
int numThreads = 8;
ExecutorService threadPool = Executors.newFixedThreadPool(numThreads);
CountDownLatch done = new CountDownLatch(numThreads);
AtomicInteger counter = new AtomicInteger();
AtomicInteger maxCounter = new AtomicInteger();
AtomicBoolean occupied = new AtomicBoolean(false);
AtomicBoolean success = new AtomicBoolean(true);

for (int i = 0; i < numThreads; i++) {
int threadnum = i;
threadPool.submit(() -> {
try (PathLock pathLock = lockManager.createPathLock("/foo/bar/baz").forReading(); //
DataLock dataLock = pathLock.lockDataForWriting()) {
LOG.trace("ENTER thread {}", threadnum);
counter.incrementAndGet();
Thread.sleep(10);
maxCounter.set(Math.max(counter.get(), maxCounter.get()));
counter.decrementAndGet();
boolean wasFree = occupied.compareAndSet(false, true);
Thread.sleep(50); // give other threads the chance to reach this point
if (!wasFree) {
success.set(false);
}
occupied.set(false);
LOG.trace("LEAVE thread {}", threadnum);
} catch (InterruptedException e) {
LOG.error("thread interrupted", e);
Expand All @@ -266,7 +261,7 @@ public void testMultipleWriteLocks() throws InterruptedException {
Assertions.assertTimeoutPreemptively(Duration.ofSeconds(10), () -> { // deadlock protection
done.await();
});
Assertions.assertEquals(1, maxCounter.get());
Assertions.assertTrue(success.get());
}

}
Expand Down
Loading

0 comments on commit e66c297

Please sign in to comment.