Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
use jndi to lookup zanata document storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Huang committed Nov 7, 2013
1 parent 2c2cea1 commit 5a178b0
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 10 deletions.
13 changes: 11 additions & 2 deletions functional-test/pom.xml
Expand Up @@ -36,6 +36,7 @@
<ds.jndi.name>zanataDatasource</ds.jndi.name>
<!--<ds.hibernate.dialect>org.hibernate.dialect.H2Dialect</ds.hibernate.dialect>-->
<ds.driver.class>org.h2.Driver</ds.driver.class>
<!--<ds.connection.url>jdbc:h2:file:${project.build.directory}/h2/zanata;AUTO_SERVER=TRUE;</ds.connection.url>-->
<ds.connection.url>jdbc:h2:file:${project.build.directory}/h2/zanata;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE</ds.connection.url>
<ds.username>sa</ds.username>
<ds.password />
Expand Down Expand Up @@ -63,7 +64,7 @@
</cargo.debug.jvm.args>
<!-- this property can be used to control what test needs to be run by failsafe -->
<include.test.patterns>**/AggregateTestSuite.java</include.test.patterns>
<document.storage.directory>${project.build.directory}/zanata-documents</document.storage.directory>
<hibernate.search.default.indexBase>${project.build.directory}/zanataindex</hibernate.search.default.indexBase>
</properties>

<dependencies>
Expand Down Expand Up @@ -345,6 +346,14 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-ejb-client-bom</artifactId>
<version>7.1.1.Final</version>
<type>pom</type>
<scope>test</scope>
</dependency>

</dependencies>

<profiles>
Expand Down Expand Up @@ -385,7 +394,7 @@
<systemProperties>
<ehcache.disk.store.dir>${project.build.directory}/ehcache</ehcache.disk.store.dir>
<jboss.server.log.threshold>WARN</jboss.server.log.threshold>
<hibernate.search.default.indexBase>${project.build.directory}/zanataindex</hibernate.search.default.indexBase>
<hibernate.search.default.indexBase>${hibernate.search.default.indexBase}</hibernate.search.default.indexBase>
</systemProperties>
</container>

Expand Down
Expand Up @@ -62,7 +62,7 @@ public class UploadTest {
public void before() {
new BasicWorkFlow().goToHome().deleteCookiesAndRefresh();
documentStorageDirectory =
PropertiesHolder.getProperty("document.storage.directory")
CleanDocumentStorageRule.getDocumentStoragePath()
.concat(File.separator).concat("documents")
.concat(File.separator);
assumeFalse("", new File(documentStorageDirectory).exists());
Expand Down
@@ -1,11 +1,16 @@
package org.zanata.util;

import com.google.common.base.Throwables;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.junit.rules.ExternalResource;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.io.File;
import java.io.IOException;
import java.util.Properties;

/**
* @author Patrick Huang <a
Expand All @@ -14,11 +19,13 @@
@Slf4j
public class CleanDocumentStorageRule extends ExternalResource {

private static String storagePath;

public static void resetFileData() {
File path =
new File(
PropertiesHolder
.getProperty("document.storage.directory"));
String documentStoragePath = getDocumentStoragePath();
log.debug("document storage path: {}", documentStoragePath);

File path = new File(documentStoragePath);
if (path.exists()) {
try {
FileUtils.deleteDirectory(path);
Expand All @@ -29,6 +36,27 @@ public static void resetFileData() {
}
}

public static String getDocumentStoragePath() {
if (storagePath == null) {
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY,
org.jboss.naming.remote.client.InitialContextFactory.class
.getName());
env.put(Context.PROVIDER_URL, "remote://localhost:4447");
InitialContext remoteContext = null;
try {
remoteContext = new InitialContext(env);
storagePath =
(String) remoteContext
.lookup("zanata/files/document-storage-directory");
}
catch (NamingException e) {
throw Throwables.propagate(e);
}
}
return storagePath;
}

@Override
protected void before() throws Throwable {
super.before();
Expand All @@ -40,4 +68,6 @@ protected void after() {
super.after();
resetFileData();
}


}
Expand Up @@ -83,7 +83,7 @@
<property name="hibernate.search.default.directory_provider"
value="org.hibernate.search.store.impl.FSDirectoryProvider" />
<property name="hibernate.search.default.indexBase"
value="/tmp/zanatasearchindex" />
value="${hibernate.search.default.indexBase}" />
<property name="hibernate.search.lucene_version" value="LUCENE_35" />
<property name="hibernate.search.worker.batch_size" value="50" />

Expand Down
2 changes: 2 additions & 0 deletions functional-test/src/test/resources/conf/standalone.xml
Expand Up @@ -244,6 +244,8 @@
value="no-reply@zanata.org" />
<simple name="java:global/zanata/files/document-storage-directory"
value="${project.build.directory}/zanata-documents" />
<lookup name="java:jboss/exported/zanata/files/document-storage-directory"
lookup="java:global/zanata/files/document-storage-directory" />
</bindings>
<remote-naming />
</subsystem>
Expand Down
2 changes: 0 additions & 2 deletions functional-test/src/test/resources/setup.properties
Expand Up @@ -10,5 +10,3 @@ webdriver.display=${webdriver.display}
zanata.instance.url=${zanata.instance.url}
zanata.sample.projects.basedir=${zanata.sample.projects.basedir}
zanata.apikey=${zanata.apikey}

document.storage.directory=${document.storage.directory}

0 comments on commit 5a178b0

Please sign in to comment.