Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
GTNPORTAL-3194: TestPlainCookieTokenService sometimes fails randomly
Browse files Browse the repository at this point in the history
  • Loading branch information
haint authored and sontran1228 committed Sep 12, 2013
1 parent 404ed48 commit 20a7be5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 36 deletions.
Expand Up @@ -229,12 +229,13 @@ public void start() {
new TokenTask<Void>() {
@Override
protected Void execute(SessionContext context) {
SessionContext ctx = chromatticLifeCycle.getContext();
ChromatticSession session = ctx.getSession();
ChromatticSession session = context.getSession();
TokenContainer container = session.findByPath(TokenContainer.class, lifecycleName);
if (container != null) {
/* if the container does not exist, it makes no sense to clean the legacy tokens */
container.cleanLegacyTokens();
} else {
session.insert(TokenContainer.class, lifecycleName);
}
return null;
}
Expand Down Expand Up @@ -391,11 +392,7 @@ private abstract class TokenTask<V> extends ContextualTask<V> {
protected final TokenContainer getTokenContainer() {
SessionContext ctx = chromatticLifeCycle.getContext();
ChromatticSession session = ctx.getSession();
TokenContainer container = session.findByPath(TokenContainer.class, lifecycleName);
if (container == null) {
container = session.insert(TokenContainer.class, lifecycleName);
}
return container;
return session.findByPath(TokenContainer.class, lifecycleName);
}

protected final <A> A getMixin(Object o, Class<A> type) {
Expand Down
Expand Up @@ -34,15 +34,6 @@
@ConfigurationUnit(scope = ContainerScope.PORTAL, path = "conf/exo.portal.component.test.jcr-configuration.xml"),
@ConfigurationUnit(scope = ContainerScope.PORTAL, path = "conf/jcr-configuration.xml") })
public abstract class AbstractCookieTokenServiceTest extends AbstractTokenServiceTest<CookieTokenService> {
protected void setUp() throws Exception {
service = createService();
Thread.sleep(1000); // for enough time initial database
}

/**
* @return
*/
protected abstract CookieTokenService createService();

@Override
public void testGetToken() throws Exception {
Expand Down Expand Up @@ -78,15 +69,21 @@ public void testDeleteToken() throws Exception {

@Override
public void testCleanExpiredTokens() throws Exception {
assertEquals(service.getValidityTime(), 2);
service.createToken(new Credentials("user1", "gtn"));
assertEquals(2, service.getValidityTime());
String tokenId1 = service.createToken(new Credentials("user1", "gtn"));

Thread.sleep(1000);
service.createToken(new Credentials("user2", "gtn"));
assertEquals(service.size(), 2);
Thread.sleep(1500);
String tokenId2 = service.createToken(new Credentials("user2", "gtn"));
service.cleanExpiredTokens();
/* Here we should be cca 2.5 seconds after the creation of user1, so it should have been cleaned as expred already */
assertEquals(service.size(), 1);
assertEquals(2, service.size());

Thread.sleep(1000);
service.cleanExpiredTokens();
assertEquals(1, service.size());

service.deleteToken(tokenId1);
service.deleteToken(tokenId2);

}

}
Expand Up @@ -33,15 +33,10 @@
*/
public class TestHashingCookieTokenService extends AbstractCookieTokenServiceTest {

/*
* (non-Javadoc)
*
* @see org.exoplatform.web.security.AbstractCookieTokenServiceTest#createService()
*/
@Override
protected CookieTokenService createService() {
protected void setUp() throws Exception {
PortalContainer container = getContainer();
return (CookieTokenService) container.getComponentInstanceOfType(CookieTokenService.class);
service = (CookieTokenService) container.getComponentInstanceOfType(CookieTokenService.class);
}

}
Expand Up @@ -31,14 +31,10 @@
*/
public class TestPlainCookieTokenService extends AbstractCookieTokenServiceTest {


/* (non-Javadoc)
* @see org.exoplatform.web.security.AbstractCookieTokenServiceTest#createService()
*/
@Override
protected CookieTokenService createService() {
protected void setUp() throws Exception {
PortalContainer container = getContainer();
return (CookieTokenService) container.getComponentInstance("org.exoplatform.web.security.security.PlainCookieTokenService");
service = (CookieTokenService) container.getComponentInstance("org.exoplatform.web.security.security.PlainCookieTokenService");
}

}

0 comments on commit 20a7be5

Please sign in to comment.