Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

Commit

Permalink
@ReadLock/@WriteLock und @synchronized Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andresteingress committed Oct 15, 2012
1 parent c3fa561 commit 8dff402
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
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'
}
}
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
}
}

0 comments on commit 8dff402

Please sign in to comment.