Author: areshetnyak
Date: 2011-11-04 03:34:42 -0400 (Fri, 04 Nov 2011)
New Revision: 5157
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/util/ConfigurationFormat.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/util/StringNumberParser.java
jcr/trunk/exo.jcr.component.core/src/main/resources/binding.xml
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestRepositoryManagement.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/util/TesterConfigurationHelper.java
Log:
EXOJCR-1566 : Problem with configuration from backup was fixed. The cause of problem is
absence special serialization method to timeout field.
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/util/ConfigurationFormat.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/util/ConfigurationFormat.java 2011-11-03
12:25:50 UTC (rev 5156)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/util/ConfigurationFormat.java 2011-11-04
07:34:42 UTC (rev 5157)
@@ -93,4 +93,17 @@
}
}
+ public static String serializeTime(long time)
+ {
+ try
+ {
+ return StringNumberParser.serializeTime(time);
+ }
+ catch (Throwable e)
+ {
+ LOG.warn("Unserialable time (as formated time) '" + time +
"'. Check StringNumberParser.serializeTime for details.", e);
+ return "";
+ }
+ }
+
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/util/StringNumberParser.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/util/StringNumberParser.java 2011-11-03
12:25:50 UTC (rev 5156)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/util/StringNumberParser.java 2011-11-04
07:34:42 UTC (rev 5157)
@@ -186,4 +186,18 @@
return Long.valueOf(text) * 1000;
}
}
+
+ /**
+ * Serialize given time in milliseconds and return a time as formated time in
milliseconds (ms).
+ *
+ * @param millisecondTime
+ * - time in milliseconds
+ * @return String
+ * - time as formated time in milliseconds
+ * @throws NumberFormatException
+ */
+ static public String serializeTime(final long millisecondTime) throws
NumberFormatException
+ {
+ return String.valueOf(millisecondTime) + "ms";
+ }
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/resources/binding.xml
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/resources/binding.xml 2011-11-03 12:25:50
UTC (rev 5156)
+++ jcr/trunk/exo.jcr.component.core/src/main/resources/binding.xml 2011-11-04 07:34:42
UTC (rev 5157)
@@ -17,8 +17,9 @@
<value name="default-workspace" field="defaultWorkspaceName"
style="attribute" />
<value name="security-domain" field="securityDomain" />
<value name="access-control" field="accessControl"
usage="optional" />
- <value name="session-max-age" field="sessionTimeOut"
-
deserializer="org.exoplatform.services.jcr.util.ConfigurationFormat.parseTime"
usage="optional" />
+ <value name="session-max-age" field="sessionTimeOut"
usage="optional"
+
serializer="org.exoplatform.services.jcr.util.ConfigurationFormat.serializeTime"
+
deserializer="org.exoplatform.services.jcr.util.ConfigurationFormat.parseTime"
/>
<value name="lock-remover-max-threads"
field="lockRemoverMaxThreadCount"
deserializer="org.exoplatform.services.jcr.util.ConfigurationFormat.parseInt"
usage="optional" />
<value name="authentication-policy"
field="authenticationPolicy" />
@@ -75,9 +76,10 @@
<collection name="properties" field="parameters"
usage="optional"
item-type="org.exoplatform.services.jcr.config.SimpleParameterEntry"
factory="org.jibx.runtime.Utility.arrayListFactory" />
- <value name="time-out" field="timeout"
usage="optional"
-
deserializer="org.exoplatform.services.jcr.util.ConfigurationFormat.parseTime"
/>
-
+ <value name="time-out" field="timeout"
usage="optional"
+
serializer="org.exoplatform.services.jcr.util.ConfigurationFormat.serializeTime"
+
deserializer="org.exoplatform.services.jcr.util.ConfigurationFormat.parseTime"
/>
+
<structure name="persister" field="persister"
usage="optional">
<value name="class" field="type"
style="attribute" />
<collection name="properties" field="parameters"
usage="optional"
Modified:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestRepositoryManagement.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestRepositoryManagement.java 2011-11-03
12:25:50 UTC (rev 5156)
+++
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestRepositoryManagement.java 2011-11-04
07:34:42 UTC (rev 5157)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.services.jcr.impl.core;
+import org.exoplatform.commons.utils.PrivilegedFileHelper;
import org.exoplatform.container.xml.PropertiesParam;
import org.exoplatform.services.jcr.JcrImplBaseTest;
import org.exoplatform.services.jcr.RepositoryService;
@@ -29,8 +30,12 @@
import org.exoplatform.services.jcr.util.TesterConfigurationHelper;
import org.jibx.runtime.BindingDirectory;
import org.jibx.runtime.IBindingFactory;
+import org.jibx.runtime.IMarshallingContext;
import org.jibx.runtime.IUnmarshallingContext;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.util.ArrayList;
import java.util.concurrent.CountDownLatch;
/**
@@ -64,6 +69,68 @@
assertNotNull(repository.login(credentials,
repository.getConfiguration().getSystemWorkspaceName()).getRootNode());
}
+ public void testMarshalUnmarshalRepositoryConfiguration() throws Exception
+ {
+ ManageableRepository newRepository = helper.createRepository(container, false,
null);
+ final long lockManagerTimeOut =
+
newRepository.getConfiguration().getWorkspaceEntries().get(0).getLockManager().getTimeout();
+
+ // 1st marshal configuration
+ File tempFile = PrivilegedFileHelper.createTempFile("test-config",
"xml");
+ PrivilegedFileHelper.deleteOnExit(tempFile);
+
+ IBindingFactory factory =
BindingDirectory.getFactory(RepositoryServiceConfiguration.class);
+ IMarshallingContext mctx = factory.createMarshallingContext();
+
+ FileOutputStream saveStream = new FileOutputStream(tempFile);
+ ArrayList<RepositoryEntry> repositoryEntries = new
ArrayList<RepositoryEntry>();
+ repositoryEntries.add(newRepository.getConfiguration());
+
+ RepositoryServiceConfiguration newRepositoryServiceConfiguration =
+ new
RepositoryServiceConfiguration(repositoryService.getConfig().getDefaultRepositoryName(),
repositoryEntries);
+ mctx.marshalDocument(newRepositoryServiceConfiguration, "ISO-8859-1",
null, saveStream);
+ saveStream.close();
+
+ // 1st unmarshal
+ factory = BindingDirectory.getFactory(RepositoryServiceConfiguration.class);
+ IUnmarshallingContext uctx = factory.createUnmarshallingContext();
+ RepositoryServiceConfiguration conf =
+
(RepositoryServiceConfiguration)uctx.unmarshalDocument(PrivilegedFileHelper.fileInputStream(tempFile),
null);
+
+ // 1st check
+ RepositoryEntry unmarshledRepositoryEntry =
+ conf.getRepositoryConfiguration(newRepository.getConfiguration().getName());
+ assertEquals(lockManagerTimeOut,
unmarshledRepositoryEntry.getWorkspaceEntries().get(0).getLockManager()
+ .getTimeout());
+
+
+ // 2nd marshal configuration
+ tempFile = PrivilegedFileHelper.createTempFile("test-config",
"xml");
+ PrivilegedFileHelper.deleteOnExit(tempFile);
+
+ factory = BindingDirectory.getFactory(RepositoryServiceConfiguration.class);
+ mctx = factory.createMarshallingContext();
+ saveStream = new FileOutputStream(tempFile);
+ repositoryEntries = new ArrayList<RepositoryEntry>();
+ repositoryEntries.add(newRepository.getConfiguration());
+
+ newRepositoryServiceConfiguration =
+ new
RepositoryServiceConfiguration(repositoryService.getConfig().getDefaultRepositoryName(),
repositoryEntries);
+ mctx.marshalDocument(newRepositoryServiceConfiguration, "ISO-8859-1",
null, saveStream);
+ saveStream.close();
+
+ // 2nd unmarshal
+ factory = BindingDirectory.getFactory(RepositoryServiceConfiguration.class);
+ uctx = factory.createUnmarshallingContext();
+ conf =
(RepositoryServiceConfiguration)uctx.unmarshalDocument(PrivilegedFileHelper.fileInputStream(tempFile),
null);
+
+ // 2nd check
+ unmarshledRepositoryEntry =
+ conf.getRepositoryConfiguration(newRepository.getConfiguration().getName());
+ assertEquals(lockManagerTimeOut,
unmarshledRepositoryEntry.getWorkspaceEntries().get(0).getLockManager()
+ .getTimeout());
+ }
+
public void testAddNewRepositoryWithSameName() throws Exception
{
ManageableRepository repository = helper.createRepository(container, false, null);
Modified:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/util/TesterConfigurationHelper.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/util/TesterConfigurationHelper.java 2011-11-03
12:25:50 UTC (rev 5156)
+++
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/util/TesterConfigurationHelper.java 2011-11-04
07:34:42 UTC (rev 5157)
@@ -224,10 +224,21 @@
CacheEntry cacheEntry = new CacheEntry(cacheParams);
cacheEntry.setType("org.exoplatform.services.jcr.impl.dataflow.persistent.LinkedWorkspaceStorageCacheImpl");
+ // Lock
+ LockManagerEntry lockManagerEntry = new LockManagerEntry();
+ lockManagerEntry.setTimeout(900000);
+ LockPersisterEntry lockPersisterEntry = new LockPersisterEntry();
+
lockPersisterEntry.setType("org.exoplatform.services.jcr.impl.core.lock.FileSystemLockPersister");
+ ArrayList<SimpleParameterEntry> lockPersisterParameters = new
ArrayList<SimpleParameterEntry>();
+ lockPersisterParameters.add(new SimpleParameterEntry("path",
"target/temp/lock/" + wsName));
+ lockPersisterEntry.setParameters(lockPersisterParameters);
+ lockManagerEntry.setPersister(lockPersisterEntry);
+
WorkspaceEntry workspaceEntry = new WorkspaceEntry();
workspaceEntry.setContainer(containerEntry);
workspaceEntry.setCache(cacheEntry);
workspaceEntry.setQueryHandler(qEntry);
+ workspaceEntry.setLockManager(lockManagerEntry);
workspaceEntry.setName(wsName);
workspaceEntry.setUniqueName(wsName);
Show replies by date