This repository has been archived by the owner on Jan 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
@ReadLock/@WriteLock und @synchronized Tests
- Loading branch information
1 parent
c3fa561
commit 8dff402
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
gcontracts-core/src/test/groovy/org/gcontracts/compability/LockTests.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.gcontracts.compability | ||
|
||
/** | ||
* User: asteingress | ||
* Date: 10/15/12 | ||
*/ | ||
class LockTests extends GroovyShellTestCase { | ||
|
||
void test_withReadAndWriteLock() { | ||
|
||
def result = evaluate """ | ||
import groovy.transform.*; | ||
import org.gcontracts.annotations.* | ||
public class ResourceProvider { | ||
private final Map<String, String> data = new HashMap<String, String>(); | ||
@Requires({ key }) | ||
@WithReadLock | ||
public String getResource(String key) throws Exception { | ||
return data.get(key); | ||
} | ||
@WithWriteLock | ||
public void refresh() throws Exception { | ||
data['test'] = 'test' | ||
} | ||
} | ||
def resourceProvider = new ResourceProvider() | ||
resourceProvider.refresh() | ||
resourceProvider.getResource('test') | ||
""" | ||
|
||
assert result == 'test' | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
gcontracts-core/src/test/groovy/org/gcontracts/compability/SynchronizedTests.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.gcontracts.compability | ||
|
||
/** | ||
* User: asteingress | ||
* Date: 10/15/12 | ||
*/ | ||
class SynchronizedTests extends GroovyShellTestCase { | ||
|
||
void test_Synchronized_on_methods() { | ||
|
||
def source = """ | ||
import org.gcontracts.annotations.* | ||
class A { | ||
@groovy.transform.Synchronized | ||
@Requires({ a >= 0 }) | ||
def m(int a) { return a} | ||
} | ||
def a = new A() | ||
a.m(12) | ||
""" | ||
|
||
evaluate source | ||
} | ||
} |