Navigation Menu

Skip to content

Commit

Permalink
more tests to prove that modelFactory implementations are synchronized
Browse files Browse the repository at this point in the history
  • Loading branch information
alexo committed Jun 8, 2012
1 parent 0164a23 commit 5f64b54
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 12 deletions.
Expand Up @@ -12,6 +12,7 @@
import org.junit.Test;

import ro.isdc.wro.config.Context;
import ro.isdc.wro.config.ContextPropagatingCallable;
import ro.isdc.wro.model.WroModel;
import ro.isdc.wro.model.transformer.WildcardExpanderModelTransformer;
import ro.isdc.wro.util.Transformer;
Expand Down Expand Up @@ -39,17 +40,17 @@ public void decoratedModelshouldBeThreadSafe()
@Override
protected InputStream getModelResourceAsStream()
throws IOException {
return TestXmlModelFactory.class.getResourceAsStream("testimport/wildcard.xml");
return TestXmlModelFactory.class.getResourceAsStream("wroWithWildcardResources.xml");
};
}, modelTransformers);
WroTestUtils.init(factory);
final WroModel expectedModel = factory.create();
WroTestUtils.runConcurrently(new Callable<Void>() {
WroTestUtils.runConcurrently(new ContextPropagatingCallable<Void>(new Callable<Void>() {
public Void call()
throws Exception {
Assert.assertEquals(expectedModel, factory.create());
return null;
}
});
}));
}
}
Expand Up @@ -10,6 +10,8 @@
import java.util.List;
import java.util.concurrent.Callable;

import junit.framework.Assert;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -19,6 +21,7 @@

import ro.isdc.wro.WroRuntimeException;
import ro.isdc.wro.config.Context;
import ro.isdc.wro.config.ContextPropagatingCallable;
import ro.isdc.wro.model.WroModel;
import ro.isdc.wro.model.group.Group;
import ro.isdc.wro.model.group.RecursiveGroupDefinitionException;
Expand Down Expand Up @@ -217,12 +220,13 @@ protected InputStream getModelResourceAsStream() {
}
};
WroTestUtils.init(factory);
WroTestUtils.runConcurrently(new Callable<Void>() {
final WroModel expected = factory.create();
WroTestUtils.runConcurrently(new ContextPropagatingCallable<Void>(new Callable<Void>() {
public Void call()
throws Exception {
factory.create();
Assert.assertEquals(expected, factory.create());
return null;
}
}, 10);
}), 10);
}
}
@@ -1,7 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<groups xmlns="http://www.isdc.ro/wro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.isdc.ro/wro wro.xsd">
<groups xmlns="http://www.isdc.ro/wro">

<import>classpath:ro/isdc/wro/model/factory/*.xml</import>

Expand Down
Expand Up @@ -2,7 +2,7 @@
<groups xmlns="http://www.isdc.ro/wro">

<group name="g1">
<css>classpath:1.css</css>
<js>classpath:ro/isdc/wro/model/factory/expander/**.js</js>
</group>

<group name="g2">
Expand Down
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<groups xmlns="http://www.isdc.ro/wro">

<group name="g1">
<css>classpath:1.css</css>
</group>

<group name="g2">
<css>/path/to/resource</css>
<js>/path/to/resource</js>
</group>

<group name="g3">
<js>/path/to/resource</js>
<group-ref>g2</group-ref>
</group>
</groups>
Expand Up @@ -42,7 +42,7 @@ public class JsonModelFactory
* {@inheritDoc}
*/
@Override
public WroModel create() {
public synchronized WroModel create() {
final StopWatch stopWatch = new StopWatch("Create Wro Model from Groovy");
try {
stopWatch.start("createModel");
Expand Down
Expand Up @@ -118,10 +118,11 @@ protected InputStream getModelResourceAsStream()
};
};
WroTestUtils.init(factory);
final WroModel expected = factory.create();
WroTestUtils.runConcurrently(new Callable<Void>() {
public Void call()
throws Exception {
factory.create();
Assert.assertEquals(expected, factory.create());
return null;
}
}, 10);
Expand Down

0 comments on commit 5f64b54

Please sign in to comment.