Skip to content

Commit

Permalink
Merge branch 'antkorwin:master' into Add_plugin_to_generate_OSGI-headers
Browse files Browse the repository at this point in the history
  • Loading branch information
shakanen authored Jun 7, 2023
2 parents 7ce9416 + 130f0d5 commit 088a223
Show file tree
Hide file tree
Showing 14 changed files with 225 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .github/branch-labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
'type:features': 'feature*'
'type:fix': 'fix*'
17 changes: 17 additions & 0 deletions .github/file-labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'type:build':
- ".github/**"
- "pom.xml"
- ".travis.yml"
- ".gitignore"
- "Dockerfile"
- ".codecov.yml"
'type:features':
- "src/main/**"
'type:tests':
- "src/test/**"
'type:documentation':
- '*.md'
- "docs/**"
'type:trash':
- ".idea/**"
- "target/**"
21 changes: 21 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name-template: 'Release $NEXT_PATCH_VERSION'
tag-template: 'v$NEXT_PATCH_VERSION'

categories:
- title: '🚀 New Features'
labels:
- 'type:features'
- title: '🐞 Bugs Fixes'
labels:
- 'type:fix'
- title: '📚 Documentation'
labels:
- 'type:documentation'
- title: '🛠 Configuration'
labels:
- 'type:config'
- 'type:build'
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
template: |
## Changes
$CHANGES
31 changes: 31 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Build

on:
pull_request:
branches:
- '*'
push:
branches:
- 'master'

jobs:
build:
runs-on: ubuntu-20.04
steps:
# checkout
- uses: actions/checkout@v3
- name: set up JDK 8
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 8

# build project and run all tests & checks
- name: Maven Verify
run: mvn -B clean verify

# Upload code coverage report to Codecov
- name: Test Coverage
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
21 changes: 21 additions & 0 deletions .github/workflows/check-and-add-labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Check and add labels in PR

on:
pull_request:
types: [ opened, labeled, unlabeled, synchronize ]

jobs:
label-verify:
name: Verify labels in PR
uses: ./.github/workflows/label-verify.yml
with:
exit_type: ${{ github.event.action == 'opened' && 'success' || 'failure' }}
labeler:
name: Auto-assign labels to PR
if: needs.label-verify.outputs.result == 'failure'
needs: label-verify
uses: ./.github/workflows/labeler.yml
retry-label-verify:
name: Retry verify labels in PR
needs: labeler
uses: ./.github/workflows/label-verify.yml
28 changes: 28 additions & 0 deletions .github/workflows/label-verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Verify labels in PR

on:
workflow_call:
inputs:
exit_type:
default: failure
required: false
type: string
outputs:
result:
value: ${{ jobs.label-verify.outputs.status }}

jobs:
label-verify:
runs-on: ubuntu-20.04
outputs:
status: ${{ steps.check-labels.outputs.status }}
steps:
- id: check-labels
uses: mheap/github-action-required-labels@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
mode: minimum
count: 1
labels: "type:fix, type:features, type:documentation, type:tests, type:config, type:build"
exit_type: ${{ inputs.exit_type }}
27 changes: 27 additions & 0 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Auto-assign labels to PR

on:
workflow_call:

jobs:
file-labeler:
name: File labeler
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-20.04
steps:
- uses: actions/labeler@v4
with:
configuration-path: .github/file-labeler.yml
repo-token: ${{ secrets.GITHUB_TOKEN }}
branch-labeler:
name: Branch labeler
needs: file-labeler
runs-on: ubuntu-20.04
steps:
- uses: TimonVS/pr-labeler-action@v3
with:
configuration-path: .github/branch-labeler.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16 changes: 16 additions & 0 deletions .github/workflows/release-draft.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Release Draft

on:
push:
branches:
- master

jobs:
update-draft-release:
permissions:
contents: write
runs-on: ubuntu-20.04
steps:
- uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28 changes: 28 additions & 0 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: SonarCloud

on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]

jobs:
sonarcloud:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
with:
# Shallow clones should be disabled for a better relevancy of analysis
fetch-depth: 0
- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 11
- name: Analyze with SonarCloud
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# run sonar maven plugin:
run: mvn -B verify sonar:sonar -Dsonar.projectKey=antkorwin_xsync -Dsonar.organization=antkorwin-github -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN -Dsonar.coverage.jacoco.xmlReportPaths=./target/site/jacoco/jacoco.xml
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build Status](https://travis-ci.com/antkorwin/xsync.svg?branch=master)](https://travis-ci.com/antkorwin/xsync)
![build status](https://github.com/antkorwin/xsync/actions/workflows/build.yml/badge.svg)
[![codecov](https://codecov.io/gh/antkorwin/xsync/branch/master/graph/badge.svg)](https://codecov.io/gh/antkorwin/xsync)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.antkorwin/xsync/badge.svg)](https://search.maven.org/search?q=g:com.antkorwin%20AND%20a:xsync)

Expand Down Expand Up @@ -148,4 +148,4 @@ You can find a project with examples here: [github.com/antkorwin/xsync-example](

## License

XSync is Open Source Software released under the [Apache 2.0 license](https://www.apache.org/licenses/LICENSE-2.0.html).
XSync is Open Source Software released under the [Apache 2.0 license](https://www.apache.org/licenses/LICENSE-2.0.html).
5 changes: 3 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.antkorwin</groupId>
<artifactId>xsync</artifactId>
<version>1.4</version>
<version>1.5</version>
<packaging>jar</packaging>

<name>XSync</name>
Expand Down Expand Up @@ -36,8 +36,9 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
<java.version>1.8</java.version>

<junit-jupiter.version>5.7.0</junit-jupiter.version>
<sonar.organization>antkorwin-github</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
</properties>

<developers>
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/com/antkorwin/xsync/XSync.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.antkorwin.xsync;

import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;

/**
* Created on 18.06.2018.
Expand Down Expand Up @@ -90,8 +88,8 @@ public void execute(KeyT firstKey, KeyT secondKey, Runnable runnable) {
XMutex<KeyT> firstMutex = mutexFactory.getMutex(firstKey);
XMutex<KeyT> secondMutex = mutexFactory.getMutex(secondKey);

int firstHash = System.identityHashCode(firstKey);
int secondHash = System.identityHashCode(secondKey);
int firstHash = System.identityHashCode(firstMutex);
int secondHash = System.identityHashCode(secondMutex);

if (firstHash > secondHash) {
XMutex<KeyT> tmp = firstMutex;
Expand Down Expand Up @@ -137,8 +135,8 @@ public <ResultT> ResultT evaluate(KeyT firstKey, KeyT secondKey, Supplier<Result
XMutex<KeyT> firstMutex = mutexFactory.getMutex(firstKey);
XMutex<KeyT> secondMutex = mutexFactory.getMutex(secondKey);

int firstHash = System.identityHashCode(firstKey);
int secondHash = System.identityHashCode(secondKey);
int firstHash = System.identityHashCode(firstMutex);
int secondHash = System.identityHashCode(secondMutex);

if (firstHash > secondHash) {
XMutex<KeyT> tmp = firstMutex;
Expand Down
25 changes: 25 additions & 0 deletions src/test/java/com/antkorwin/xsync/XSyncTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import static org.awaitility.Awaitility.await;
import static org.hamcrest.Matchers.equalTo;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
Expand Down Expand Up @@ -221,4 +223,27 @@ public void xSyncWithDifferentMutexFactoriesDoesntLock() {

assertThat(sum).isLessThan(ITERATION_COUNT);
}

@Test
void testDeadlockWithTwoKeys() {
// Arrange
XSync<Long> xSync = new XSync<>();

// Act
StressTestRunner.test()
.iterations(ITERATION_COUNT)
.threads(8)
.mode(ExecutionMode.EXECUTOR_MODE)
// deadlock prevention
.timeout(1, TimeUnit.MINUTES)
.run(() -> {
Long id1 = 128L;
Long id2 = 129L;
xSync.execute(id1, id2, () -> {});
});

// Assert
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
assertThat(threadMXBean.findDeadlockedThreads()).isNull();
}
}

0 comments on commit 088a223

Please sign in to comment.