Merge branch 'serializable'

This commit is contained in:
Havoc Pennington 2012-02-09 13:46:10 -05:00
commit dc2f52aa24
54 changed files with 555 additions and 61 deletions

View File

@ -18,6 +18,8 @@ libraryDependencies += "net.liftweb" %% "lift-json" % "2.4-SNAPSHOT" % "test"
libraryDependencies += "com.novocode" % "junit-interface" % "0.7" % "test"
libraryDependencies += "commons-codec" % "commons-codec" % "1.4" % "test"
externalResolvers += "Scala Tools Snapshots" at "http://scala-tools.org/repo-snapshots/"
seq(findbugsSettings : _*)

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config;
@ -378,10 +378,11 @@ public interface Config extends ConfigMergeable {
Object getAnyRef(String path);
/**
* Gets the value at the given path, unless the value is a null value or
* missing, in which case it throws just like the other getters. Use
* {@code get()} from the {@link java.util.Map Map} interface if you want an
* unprocessed value.
* Gets the value at the given path, unless the value is a
* null value or missing, in which case it throws just like
* the other getters. Use {@code get()} on the {@link
* Config#root()} object (or other object in the tree) if you
* want an unprocessed value.
*
* @param path
* path expression

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config;
@ -161,8 +161,8 @@ public final class ConfigFactory {
* used rather than the default
* <code>application.{conf,json,properties}</code> classpath resources.
* These system properties should not be set in code (after all, you can
* just parse whatever you want manually and then use {@link #load(Config)
* if you don't want to use <code>application.conf</code>}). The properties
* just parse whatever you want manually and then use {@link #load(Config)}
* if you don't want to use <code>application.conf</code>). The properties
* are intended for use by the person or script launching the application.
* For example someone might have a <code>production.conf</code> that
* include <code>application.conf</code> but then change a couple of values.

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;
@ -23,6 +23,9 @@ import com.typesafe.config.ConfigValueType;
abstract class AbstractConfigObject extends AbstractConfigValue implements
ConfigObject {
private static final long serialVersionUID = 1L;
final private SimpleConfig config;
protected AbstractConfigObject(ConfigOrigin origin) {

View File

@ -1,8 +1,10 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;
import java.io.Serializable;
import com.typesafe.config.ConfigException;
import com.typesafe.config.ConfigMergeable;
import com.typesafe.config.ConfigOrigin;
@ -16,7 +18,9 @@ import com.typesafe.config.ConfigValue;
* improperly-factored and non-modular code. Please don't add parent().
*
*/
abstract class AbstractConfigValue implements ConfigValue, MergeableValue {
abstract class AbstractConfigValue implements ConfigValue, MergeableValue, Serializable {
private static final long serialVersionUID = 1L;
final private SimpleConfigOrigin origin;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;
@ -8,6 +8,8 @@ import com.typesafe.config.ConfigValueType;
final class ConfigBoolean extends AbstractConfigValue {
private static final long serialVersionUID = 1L;
final private boolean value;
ConfigBoolean(ConfigOrigin origin, boolean value) {

View File

@ -1,8 +1,9 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;
import java.io.ObjectStreamException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -228,4 +229,14 @@ final class ConfigDelayedMerge extends AbstractConfigValue implements
sb.append("# ) end of unresolved merge\n");
}
}
// This ridiculous hack is because some JDK versions apparently can't
// serialize an array, which is used to implement ArrayList and EmptyList.
// maybe
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6446627
private Object writeReplace() throws ObjectStreamException {
// switch to LinkedList
return new ConfigDelayedMerge(origin(),
new java.util.LinkedList<AbstractConfigValue>(stack), ignoresFallbacks);
}
}

View File

@ -1,8 +1,9 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;
import java.io.ObjectStreamException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@ -192,4 +193,14 @@ class ConfigDelayedMergeObject extends AbstractConfigObject implements
protected AbstractConfigValue peek(String key) {
throw notResolved();
}
// This ridiculous hack is because some JDK versions apparently can't
// serialize an array, which is used to implement ArrayList and EmptyList.
// maybe
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6446627
private Object writeReplace() throws ObjectStreamException {
// switch to LinkedList
return new ConfigDelayedMergeObject(origin(),
new java.util.LinkedList<AbstractConfigValue>(stack), ignoresFallbacks);
}
}

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;
@ -8,6 +8,8 @@ import com.typesafe.config.ConfigValueType;
final class ConfigDouble extends ConfigNumber {
private static final long serialVersionUID = 1L;
final private double value;
ConfigDouble(ConfigOrigin origin, double value, String originalText) {

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;
@ -8,6 +8,8 @@ import com.typesafe.config.ConfigValueType;
final class ConfigInt extends ConfigNumber {
private static final long serialVersionUID = 1L;
final private int value;
ConfigInt(ConfigOrigin origin, int value, String originalText) {

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;
@ -8,6 +8,8 @@ import com.typesafe.config.ConfigValueType;
final class ConfigLong extends ConfigNumber {
private static final long serialVersionUID = 1L;
final private long value;
ConfigLong(ConfigOrigin origin, long value, String originalText) {

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;
@ -16,6 +16,8 @@ import com.typesafe.config.ConfigValueType;
*/
final class ConfigNull extends AbstractConfigValue {
private static final long serialVersionUID = 1L;
ConfigNull(ConfigOrigin origin) {
super(origin);
}

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;
@ -7,6 +7,9 @@ import com.typesafe.config.ConfigException;
import com.typesafe.config.ConfigOrigin;
abstract class ConfigNumber extends AbstractConfigValue {
private static final long serialVersionUID = 1L;
// This is so when we concatenate a number into a string (say it appears in
// a sentence) we always have it exactly as the person typed it into the
// config file. It's purely cosmetic; equals/hashCode don't consider this

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;
@ -8,6 +8,8 @@ import com.typesafe.config.ConfigValueType;
final class ConfigString extends AbstractConfigValue {
private static final long serialVersionUID = 1L;
final private String value;
ConfigString(ConfigOrigin origin, String value) {

View File

@ -1,8 +1,9 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;
import java.io.ObjectStreamException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -284,4 +285,14 @@ final class ConfigSubstitution extends AbstractConfigValue implements
}
}
}
// This ridiculous hack is because some JDK versions apparently can't
// serialize an array, which is used to implement ArrayList and EmptyList.
// maybe
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6446627
private Object writeReplace() throws ObjectStreamException {
// switch to LinkedList
return new ConfigSubstitution(origin(), new java.util.LinkedList<Object>(pieces),
prefixLength, ignoresFallbacks);
}
}

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;

View File

@ -1,14 +1,17 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;
import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
import com.typesafe.config.ConfigException;
final class Path {
final class Path implements Serializable {
private static final long serialVersionUID = 1L;
final private String first;
final private Path remainder;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;

View File

@ -1,8 +1,9 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;
import java.io.Serializable;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.HashMap;
@ -28,7 +29,9 @@ import com.typesafe.config.ConfigValueType;
* with a one-level java.util.Map from paths to non-null values. Null values are
* not "in" the map.
*/
final class SimpleConfig implements Config, MergeableValue {
final class SimpleConfig implements Config, MergeableValue, Serializable {
private static final long serialVersionUID = 1L;
final private AbstractConfigObject object;

View File

@ -1,8 +1,9 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;
import java.io.ObjectStreamException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
@ -21,7 +22,8 @@ final class SimpleConfigList extends AbstractConfigValue implements ConfigList {
final private boolean resolved;
SimpleConfigList(ConfigOrigin origin, List<AbstractConfigValue> value) {
this(origin, value, ResolveStatus.fromValues(value));
this(origin, value, ResolveStatus
.fromValues(value));
}
SimpleConfigList(ConfigOrigin origin, List<AbstractConfigValue> value,
@ -366,4 +368,14 @@ final class SimpleConfigList extends AbstractConfigValue implements ConfigList {
protected SimpleConfigList newCopy(boolean ignoresFallbacks, ConfigOrigin newOrigin) {
return new SimpleConfigList(newOrigin, value);
}
// This ridiculous hack is because some JDK versions apparently can't
// serialize an array, which is used to implement ArrayList and EmptyList.
// maybe
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6446627
private Object writeReplace() throws ObjectStreamException {
// switch to LinkedList
return new SimpleConfigList(origin(), new java.util.LinkedList<AbstractConfigValue>(value),
resolveStatus());
}
}

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;
@ -17,6 +17,8 @@ import com.typesafe.config.ConfigValue;
final class SimpleConfigObject extends AbstractConfigObject {
private static final long serialVersionUID = 1L;
// this map should never be modified - assume immutable
final private Map<String, AbstractConfigValue> value;
final private boolean resolved;

View File

@ -1,9 +1,10 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;
import java.io.File;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
@ -17,7 +18,10 @@ import com.typesafe.config.ConfigOrigin;
// it would be cleaner to have a class hierarchy for various origin types,
// but was hoping this would be enough simpler to be a little messy. eh.
final class SimpleConfigOrigin implements ConfigOrigin {
final class SimpleConfigOrigin implements ConfigOrigin, Serializable {
private static final long serialVersionUID = 1L;
final private String description;
final private int lineNumber;
final private int endLineNumber;

View File

@ -1,6 +1,10 @@
package com.typesafe.config.impl;
final class SubstitutionExpression {
import java.io.Serializable;
final class SubstitutionExpression implements Serializable {
private static final long serialVersionUID = 1L;
final private Path path;
final private boolean optional;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;

View File

@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Typesafe Inc. <http://typesafe.com>
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;

View File

@ -322,6 +322,89 @@ class ConfigSubstitutionTest extends TestUtils {
""")
}
@Test
def serializeUnresolvedObject() {
val expectedSerialization = "" +
"aced00057372002b636f6d2e74797065736166652e636f6e6669672e696d706c2e53696d706c6543" +
"6f6e6669674f626a65637400000000000000010200035a001069676e6f72657346616c6c6261636b" +
"735a00087265736f6c7665644c000576616c756574000f4c6a6176612f7574696c2f4d61703b7872" +
"002d636f6d2e74797065736166652e636f6e6669672e696d706c2e4162737472616374436f6e6669" +
"674f626a65637400000000000000010200014c0006636f6e6669677400274c636f6d2f7479706573" +
"6166652f636f6e6669672f696d706c2f53696d706c65436f6e6669673b7872002c636f6d2e747970" +
"65736166652e636f6e6669672e696d706c2e4162737472616374436f6e66696756616c7565000000" +
"00000000010200014c00066f726967696e74002d4c636f6d2f74797065736166652f636f6e666967" +
"2f696d706c2f53696d706c65436f6e6669674f726967696e3b78707372002b636f6d2e7479706573" +
"6166652e636f6e6669672e696d706c2e53696d706c65436f6e6669674f726967696e000000000000" +
"000102000649000d656e644c696e654e756d62657249000a6c696e654e756d6265724c000e636f6d" +
"6d656e74734f724e756c6c7400104c6a6176612f7574696c2f4c6973743b4c000b64657363726970" +
"74696f6e7400124c6a6176612f6c616e672f537472696e673b4c000a6f726967696e547970657400" +
"254c636f6d2f74797065736166652f636f6e6669672f696d706c2f4f726967696e547970653b4c00" +
"0975726c4f724e756c6c71007e0009787000000002000000027074000b7465737420737472696e67" +
"7e720023636f6d2e74797065736166652e636f6e6669672e696d706c2e4f726967696e5479706500" +
"000000000000001200007872000e6a6176612e6c616e672e456e756d000000000000000012000078" +
"7074000747454e455249437073720025636f6d2e74797065736166652e636f6e6669672e696d706c" +
"2e53696d706c65436f6e66696700000000000000010200014c00066f626a65637474002f4c636f6d" +
"2f74797065736166652f636f6e6669672f696d706c2f4162737472616374436f6e6669674f626a65" +
"63743b787071007e00060000737200116a6176612e7574696c2e486173684d61700507dac1c31660" +
"d103000246000a6c6f6164466163746f724900097468726573686f6c6478703f4000000000000c77" +
"08000000100000000a7400046f626a457372002b636f6d2e74797065736166652e636f6e6669672e" +
"696d706c2e436f6e666967537562737469747574696f6e61f02fc05eca6d7d0200035a001069676e" +
"6f72657346616c6c6261636b7349000c7072656669784c656e6774684c000670696563657371007e" +
"00087871007e00047371007e000700000008000000087071007e000c71007e000f70000000000073" +
"7200146a6176612e7574696c2e4c696e6b65644c6973740c29535d4a608822030000787077040000" +
"00017372002f636f6d2e74797065736166652e636f6e6669672e696d706c2e537562737469747574" +
"696f6e45787072657373696f6e00000000000000010200025a00086f7074696f6e616c4c00047061" +
"746874001f4c636f6d2f74797065736166652f636f6e6669672f696d706c2f506174683b78700073" +
"72001d636f6d2e74797065736166652e636f6e6669672e696d706c2e506174680000000000000001" +
"0200024c0005666972737471007e00094c000972656d61696e64657271007e001d78707400016173" +
"71007e001f740001627371007e001f740001657078740007666f6f2e62617273720022636f6d2e74" +
"797065736166652e636f6e6669672e696d706c2e436f6e666967496e740000000000000001020001" +
"49000576616c756578720025636f6d2e74797065736166652e636f6e6669672e696d706c2e436f6e" +
"6669674e756d62657200000000000000010200014c000c6f726967696e616c5465787471007e0009" +
"7871007e00047371007e000700000009000000097071007e000c71007e000f707400023337000000" +
"257400046f626a427371007e00177371007e000700000007000000077071007e000c71007e000f70" +
"00000000007371007e001a7704000000017371007e001c007371007e001f740001617371007e001f" +
"74000162707874000361727273720029636f6d2e74797065736166652e636f6e6669672e696d706c" +
"2e53696d706c65436f6e6669674c697374ef9443c7c6af330d0200025a00087265736f6c7665644c" +
"000576616c756571007e00087871007e00047371007e00070000000a0000000a7071007e000c7100" +
"7e000f70007371007e001a7704000000067371007e00177371007e00070000000a0000000a707100" +
"7e000c71007e000f7000000000007371007e001a7704000000017371007e001c007371007e001f74" +
"0003666f6f70787371007e001771007e003b00000000007371007e001a7704000000017371007e00" +
"1c007371007e001f740001617371007e001f740001627371007e001f7400016370787371007e0017" +
"71007e003b00000000007371007e001a7704000000017371007e001c007371007e001f740007666f" +
"6f2e62617270787371007e001771007e003b00000000007371007e001a7704000000017371007e00" +
"1c007371007e001f7400046f626a427371007e001f7400016470787371007e001771007e003b0000" +
"0000007371007e001a7704000000017371007e001c007371007e001f7400046f626a417371007e00" +
"1f740001627371007e001f740001657371007e001f7400016670787371007e001771007e003b0000" +
"0000007371007e001a7704000000017371007e001c007371007e001f7400046f626a457371007e00" +
"1f740001667078787400046f626a417371007e00177371007e000700000006000000067071007e00" +
"0c71007e000f7000000000007371007e001a7704000000017371007e001c007371007e001f740001" +
"617078740001617371007e00007371007e000700000005000000057071007e000c71007e000f7073" +
"71007e001171007e006f00007371007e00143f4000000000000c7708000000100000000174000162" +
"7371007e00007371007e000700000005000000057071007e000c71007e000f707371007e00117100" +
"7e007400007371007e00143f4000000000000c77080000001000000003740001647371007e001773" +
"71007e000700000005000000057071007e000c71007e000f7000000000007371007e001a77040000" +
"00017371007e001c007371007e001f740003666f6f7078740001657371007e00007371007e000700" +
"000005000000057071007e000c71007e000f707371007e001171007e008000007371007e00143f40" +
"00000000000c77080000001000000001740001667371007e001771007e007a00000000007371007e" +
"001a7704000000017371007e001c007371007e001f740003666f6f707878740001637371007e0027" +
"71007e007a7400023537000000397878740003666f6f7371007e00177371007e0007000000030000" +
"00037071007e000c71007e000f7000000000007371007e001a7704000000017371007e001c007371" +
"007e001f7400036261727078740008707472546f4172727371007e00177371007e00070000000b00" +
"00000b7071007e000c71007e000f7000000000007371007e001a7704000000017371007e001c0073" +
"71007e001f74000361727270787400036261727371007e00177371007e0007000000040000000470" +
"71007e000c71007e000f7000000000007371007e001a7704000000017371007e001c007371007e00" +
"1f740001617371007e001f740001627371007e001f740001637078740001787371007e0000737100" +
"7e00070000000c0000000c7071007e000c71007e000f707371007e001171007e00a700007371007e" +
"00143f4000000000000c77080000001000000001740001797371007e00007371007e00070000000c" +
"0000000c7071007e000c71007e000f707371007e001171007e00ac00007371007e00143f40000000" +
"00000c7708000000100000000174000d707472546f507472546f4172727371007e00177371007e00" +
"070000000c0000000c7071007e000c71007e000f7000000000007371007e001a7704000000017371" +
"007e001c007371007e001f740008707472546f4172727078787878"
checkSerializable(expectedSerialization, substComplexObject)
}
// this is a weird test, it used to test fallback to system props which made more sense.
// Now it just tests that if you override with system props, you can use system props
// in substitutions.

View File

@ -792,6 +792,12 @@ class ConfigTest extends TestUtils {
assertEquals(None, entries.get("nulls.null"))
}
@Test
def test01Serializable() {
val conf = ConfigFactory.load("test01")
val confCopy = checkSerializable(conf)
}
@Test
def test02SubstitutionsWithWeirdPaths() {
val conf = ConfigFactory.load("test02")

View File

@ -28,6 +28,23 @@ class ConfigValueTest extends TestUtils {
checkNotEqualObjects(a, b)
}
@Test
def configOriginSerializable() {
val expectedSerialization = "" +
"aced00057372002b636f6d2e74797065736166652e636f6e6669672e696d706c2e53696d706c6543" +
"6f6e6669674f726967696e000000000000000102000649000d656e644c696e654e756d6265724900" +
"0a6c696e654e756d6265724c000e636f6d6d656e74734f724e756c6c7400104c6a6176612f757469" +
"6c2f4c6973743b4c000b6465736372697074696f6e7400124c6a6176612f6c616e672f537472696e" +
"673b4c000a6f726967696e547970657400254c636f6d2f74797065736166652f636f6e6669672f69" +
"6d706c2f4f726967696e547970653b4c000975726c4f724e756c6c71007e00027870ffffffffffff" +
"ffff70740003666f6f7e720023636f6d2e74797065736166652e636f6e6669672e696d706c2e4f72" +
"6967696e5479706500000000000000001200007872000e6a6176612e6c616e672e456e756d000000" +
"0000000000120000787074000747454e4552494370"
val a = SimpleConfigOrigin.newSimple("foo")
checkSerializable(expectedSerialization, a)
}
@Test
def configIntEquality() {
val a = intValue(42)
@ -39,6 +56,31 @@ class ConfigValueTest extends TestUtils {
checkNotEqualObjects(a, b)
}
@Test
def configIntSerializable() {
val expectedSerialization = "" +
"aced000573720022636f6d2e74797065736166652e636f6e6669672e696d706c2e436f6e66696749" +
"6e74000000000000000102000149000576616c756578720025636f6d2e74797065736166652e636f" +
"6e6669672e696d706c2e436f6e6669674e756d62657200000000000000010200014c000c6f726967" +
"696e616c546578747400124c6a6176612f6c616e672f537472696e673b7872002c636f6d2e747970" +
"65736166652e636f6e6669672e696d706c2e4162737472616374436f6e66696756616c7565000000" +
"00000000010200014c00066f726967696e74002d4c636f6d2f74797065736166652f636f6e666967" +
"2f696d706c2f53696d706c65436f6e6669674f726967696e3b78707372002b636f6d2e7479706573" +
"6166652e636f6e6669672e696d706c2e53696d706c65436f6e6669674f726967696e000000000000" +
"000102000649000d656e644c696e654e756d62657249000a6c696e654e756d6265724c000e636f6d" +
"6d656e74734f724e756c6c7400104c6a6176612f7574696c2f4c6973743b4c000b64657363726970" +
"74696f6e71007e00024c000a6f726967696e547970657400254c636f6d2f74797065736166652f63" +
"6f6e6669672f696d706c2f4f726967696e547970653b4c000975726c4f724e756c6c71007e000278" +
"70ffffffffffffffff7074000b66616b65206f726967696e7e720023636f6d2e7479706573616665" +
"2e636f6e6669672e696d706c2e4f726967696e5479706500000000000000001200007872000e6a61" +
"76612e6c616e672e456e756d0000000000000000120000787074000747454e455249437070000000" +
"2a"
val a = intValue(42)
val b = checkSerializable(expectedSerialization, a)
assertEquals(42, b.unwrapped)
}
@Test
def configLongEquality() {
val a = longValue(Integer.MAX_VALUE + 42L)
@ -104,6 +146,47 @@ class ConfigValueTest extends TestUtils {
checkNotEqualObjects(b, b.toConfig())
}
@Test
def configObjectSerializable() {
val expectedSerialization = "" +
"aced00057372002b636f6d2e74797065736166652e636f6e6669672e696d706c2e53696d706c6543" +
"6f6e6669674f626a65637400000000000000010200035a001069676e6f72657346616c6c6261636b" +
"735a00087265736f6c7665644c000576616c756574000f4c6a6176612f7574696c2f4d61703b7872" +
"002d636f6d2e74797065736166652e636f6e6669672e696d706c2e4162737472616374436f6e6669" +
"674f626a65637400000000000000010200014c0006636f6e6669677400274c636f6d2f7479706573" +
"6166652f636f6e6669672f696d706c2f53696d706c65436f6e6669673b7872002c636f6d2e747970" +
"65736166652e636f6e6669672e696d706c2e4162737472616374436f6e66696756616c7565000000" +
"00000000010200014c00066f726967696e74002d4c636f6d2f74797065736166652f636f6e666967" +
"2f696d706c2f53696d706c65436f6e6669674f726967696e3b78707372002b636f6d2e7479706573" +
"6166652e636f6e6669672e696d706c2e53696d706c65436f6e6669674f726967696e000000000000" +
"000102000649000d656e644c696e654e756d62657249000a6c696e654e756d6265724c000e636f6d" +
"6d656e74734f724e756c6c7400104c6a6176612f7574696c2f4c6973743b4c000b64657363726970" +
"74696f6e7400124c6a6176612f6c616e672f537472696e673b4c000a6f726967696e547970657400" +
"254c636f6d2f74797065736166652f636f6e6669672f696d706c2f4f726967696e547970653b4c00" +
"0975726c4f724e756c6c71007e00097870ffffffffffffffff7074000b66616b65206f726967696e" +
"7e720023636f6d2e74797065736166652e636f6e6669672e696d706c2e4f726967696e5479706500" +
"000000000000001200007872000e6a6176612e6c616e672e456e756d000000000000000012000078" +
"7074000747454e455249437073720025636f6d2e74797065736166652e636f6e6669672e696d706c" +
"2e53696d706c65436f6e66696700000000000000010200014c00066f626a65637474002f4c636f6d" +
"2f74797065736166652f636f6e6669672f696d706c2f4162737472616374436f6e6669674f626a65" +
"63743b787071007e00060001737200116a6176612e7574696c2e486173684d61700507dac1c31660" +
"d103000246000a6c6f6164466163746f724900097468726573686f6c6478703f4000000000000c77" +
"0800000010000000037400016273720022636f6d2e74797065736166652e636f6e6669672e696d70" +
"6c2e436f6e666967496e74000000000000000102000149000576616c756578720025636f6d2e7479" +
"7065736166652e636f6e6669672e696d706c2e436f6e6669674e756d626572000000000000000102" +
"00014c000c6f726967696e616c5465787471007e00097871007e00047371007e0007ffffffffffff" +
"ffff7071007e000c71007e000f707000000002740001637371007e00177371007e0007ffffffffff" +
"ffffff7071007e000c71007e000f707000000003740001617371007e00177371007e0007ffffffff" +
"ffffffff7071007e000c71007e000f70700000000178"
val aMap = configMap("a" -> 1, "b" -> 2, "c" -> 3)
val a = new SimpleConfigObject(fakeOrigin(), aMap)
val b = checkSerializable(expectedSerialization, a)
assertEquals(1, b.toConfig.getInt("a"))
// check that deserialized Config and ConfigObject refer to each other
assertTrue(b.toConfig.root eq b)
}
@Test
def configListEquality() {
val aScalaSeq = Seq(1, 2, 3) map { intValue(_): AbstractConfigValue }
@ -117,6 +200,37 @@ class ConfigValueTest extends TestUtils {
checkNotEqualObjects(aList, bList)
}
@Test
def configListSerializable() {
val expectedSerialization = "" +
"aced000573720029636f6d2e74797065736166652e636f6e6669672e696d706c2e53696d706c6543" +
"6f6e6669674c697374ef9443c7c6af330d0200025a00087265736f6c7665644c000576616c756574" +
"00104c6a6176612f7574696c2f4c6973743b7872002c636f6d2e74797065736166652e636f6e6669" +
"672e696d706c2e4162737472616374436f6e66696756616c756500000000000000010200014c0006" +
"6f726967696e74002d4c636f6d2f74797065736166652f636f6e6669672f696d706c2f53696d706c" +
"65436f6e6669674f726967696e3b78707372002b636f6d2e74797065736166652e636f6e6669672e" +
"696d706c2e53696d706c65436f6e6669674f726967696e000000000000000102000649000d656e64" +
"4c696e654e756d62657249000a6c696e654e756d6265724c000e636f6d6d656e74734f724e756c6c" +
"71007e00014c000b6465736372697074696f6e7400124c6a6176612f6c616e672f537472696e673b" +
"4c000a6f726967696e547970657400254c636f6d2f74797065736166652f636f6e6669672f696d70" +
"6c2f4f726967696e547970653b4c000975726c4f724e756c6c71007e00067870ffffffffffffffff" +
"7074000b66616b65206f726967696e7e720023636f6d2e74797065736166652e636f6e6669672e69" +
"6d706c2e4f726967696e5479706500000000000000001200007872000e6a6176612e6c616e672e45" +
"6e756d0000000000000000120000787074000747454e455249437001737200146a6176612e757469" +
"6c2e4c696e6b65644c6973740c29535d4a608822030000787077040000000373720022636f6d2e74" +
"797065736166652e636f6e6669672e696d706c2e436f6e666967496e740000000000000001020001" +
"49000576616c756578720025636f6d2e74797065736166652e636f6e6669672e696d706c2e436f6e" +
"6669674e756d62657200000000000000010200014c000c6f726967696e616c5465787471007e0006" +
"7871007e00027371007e0005ffffffffffffffff7071007e000971007e000c707000000001737100" +
"7e00107371007e0005ffffffffffffffff7071007e000971007e000c7070000000027371007e0010" +
"7371007e0005ffffffffffffffff7071007e000971007e000c70700000000378"
val aScalaSeq = Seq(1, 2, 3) map { intValue(_): AbstractConfigValue }
val aList = new SimpleConfigList(fakeOrigin(), aScalaSeq.asJava)
val bList = checkSerializable(expectedSerialization, aList)
assertEquals(1, bList.get(0).unwrapped())
}
@Test
def configSubstitutionEquality() {
val a = subst("foo")
@ -128,6 +242,35 @@ class ConfigValueTest extends TestUtils {
checkNotEqualObjects(a, b)
}
@Test
def configSubstitutionSerializable() {
val expectedSerialization = "" +
"aced00057372002b636f6d2e74797065736166652e636f6e6669672e696d706c2e436f6e66696753" +
"7562737469747574696f6e61f02fc05eca6d7d0200035a001069676e6f72657346616c6c6261636b" +
"7349000c7072656669784c656e6774684c00067069656365737400104c6a6176612f7574696c2f4c" +
"6973743b7872002c636f6d2e74797065736166652e636f6e6669672e696d706c2e41627374726163" +
"74436f6e66696756616c756500000000000000010200014c00066f726967696e74002d4c636f6d2f" +
"74797065736166652f636f6e6669672f696d706c2f53696d706c65436f6e6669674f726967696e3b" +
"78707372002b636f6d2e74797065736166652e636f6e6669672e696d706c2e53696d706c65436f6e" +
"6669674f726967696e000000000000000102000649000d656e644c696e654e756d62657249000a6c" +
"696e654e756d6265724c000e636f6d6d656e74734f724e756c6c71007e00014c000b646573637269" +
"7074696f6e7400124c6a6176612f6c616e672f537472696e673b4c000a6f726967696e5479706574" +
"00254c636f6d2f74797065736166652f636f6e6669672f696d706c2f4f726967696e547970653b4c" +
"000975726c4f724e756c6c71007e00067870ffffffffffffffff7074000b66616b65206f72696769" +
"6e7e720023636f6d2e74797065736166652e636f6e6669672e696d706c2e4f726967696e54797065" +
"00000000000000001200007872000e6a6176612e6c616e672e456e756d0000000000000000120000" +
"787074000747454e45524943700000000000737200146a6176612e7574696c2e4c696e6b65644c69" +
"73740c29535d4a60882203000078707704000000017372002f636f6d2e74797065736166652e636f" +
"6e6669672e696d706c2e537562737469747574696f6e45787072657373696f6e0000000000000001" +
"0200025a00086f7074696f6e616c4c00047061746874001f4c636f6d2f74797065736166652f636f" +
"6e6669672f696d706c2f506174683b7870007372001d636f6d2e74797065736166652e636f6e6669" +
"672e696d706c2e5061746800000000000000010200024c0005666972737471007e00064c00097265" +
"6d61696e64657271007e00117870740003666f6f7078"
val a = subst("foo")
val b = checkSerializable(expectedSerialization, a)
}
@Test
def configDelayedMergeEquality() {
val s1 = subst("foo")
@ -141,6 +284,42 @@ class ConfigValueTest extends TestUtils {
checkNotEqualObjects(a, b)
}
@Test
def configDelayedMergeSerializable() {
val expectedSerialization = "" +
"aced00057372002b636f6d2e74797065736166652e636f6e6669672e696d706c2e436f6e66696744" +
"656c617965644d657267656d8c8e0e0c0145760200025a001069676e6f72657346616c6c6261636b" +
"734c0005737461636b7400104c6a6176612f7574696c2f4c6973743b7872002c636f6d2e74797065" +
"736166652e636f6e6669672e696d706c2e4162737472616374436f6e66696756616c756500000000" +
"000000010200014c00066f726967696e74002d4c636f6d2f74797065736166652f636f6e6669672f" +
"696d706c2f53696d706c65436f6e6669674f726967696e3b78707372002b636f6d2e747970657361" +
"66652e636f6e6669672e696d706c2e53696d706c65436f6e6669674f726967696e00000000000000" +
"0102000649000d656e644c696e654e756d62657249000a6c696e654e756d6265724c000e636f6d6d" +
"656e74734f724e756c6c71007e00014c000b6465736372697074696f6e7400124c6a6176612f6c61" +
"6e672f537472696e673b4c000a6f726967696e547970657400254c636f6d2f74797065736166652f" +
"636f6e6669672f696d706c2f4f726967696e547970653b4c000975726c4f724e756c6c71007e0006" +
"7870ffffffffffffffff7074000b66616b65206f726967696e7e720023636f6d2e74797065736166" +
"652e636f6e6669672e696d706c2e4f726967696e5479706500000000000000001200007872000e6a" +
"6176612e6c616e672e456e756d0000000000000000120000787074000747454e4552494370007372" +
"00146a6176612e7574696c2e4c696e6b65644c6973740c29535d4a60882203000078707704000000" +
"027372002b636f6d2e74797065736166652e636f6e6669672e696d706c2e436f6e66696753756273" +
"7469747574696f6e61f02fc05eca6d7d0200035a001069676e6f72657346616c6c6261636b734900" +
"0c7072656669784c656e6774684c000670696563657371007e00017871007e00027371007e0005ff" +
"ffffffffffffff7071007e000971007e000c7000000000007371007e000e7704000000017372002f" +
"636f6d2e74797065736166652e636f6e6669672e696d706c2e537562737469747574696f6e457870" +
"72657373696f6e00000000000000010200025a00086f7074696f6e616c4c00047061746874001f4c" +
"636f6d2f74797065736166652f636f6e6669672f696d706c2f506174683b7870007372001d636f6d" +
"2e74797065736166652e636f6e6669672e696d706c2e5061746800000000000000010200024c0005" +
"666972737471007e00064c000972656d61696e64657271007e00157870740003666f6f7078737100" +
"7e00107371007e0005ffffffffffffffff7071007e000971007e000c7000000000007371007e000e" +
"7704000000017371007e0014007371007e0017740003626172707878"
val s1 = subst("foo")
val s2 = subst("bar")
val a = new ConfigDelayedMerge(fakeOrigin(), List[AbstractConfigValue](s1, s2).asJava)
val b = checkSerializable(expectedSerialization, a)
}
@Test
def configDelayedMergeObjectEquality() {
val empty = SimpleConfigObject.empty()
@ -155,6 +334,54 @@ class ConfigValueTest extends TestUtils {
checkNotEqualObjects(a, b)
}
@Test
def configDelayedMergeObjectSerializable() {
val expectedSerialization = "" +
"aced000573720031636f6d2e74797065736166652e636f6e6669672e696d706c2e436f6e66696744" +
"656c617965644d657267654f626a65637401fa1552304cae900200025a001069676e6f7265734661" +
"6c6c6261636b734c0005737461636b7400104c6a6176612f7574696c2f4c6973743b7872002d636f" +
"6d2e74797065736166652e636f6e6669672e696d706c2e4162737472616374436f6e6669674f626a" +
"65637400000000000000010200014c0006636f6e6669677400274c636f6d2f74797065736166652f" +
"636f6e6669672f696d706c2f53696d706c65436f6e6669673b7872002c636f6d2e74797065736166" +
"652e636f6e6669672e696d706c2e4162737472616374436f6e66696756616c756500000000000000" +
"010200014c00066f726967696e74002d4c636f6d2f74797065736166652f636f6e6669672f696d70" +
"6c2f53696d706c65436f6e6669674f726967696e3b78707372002b636f6d2e74797065736166652e" +
"636f6e6669672e696d706c2e53696d706c65436f6e6669674f726967696e00000000000000010200" +
"0649000d656e644c696e654e756d62657249000a6c696e654e756d6265724c000e636f6d6d656e74" +
"734f724e756c6c71007e00014c000b6465736372697074696f6e7400124c6a6176612f6c616e672f" +
"537472696e673b4c000a6f726967696e547970657400254c636f6d2f74797065736166652f636f6e" +
"6669672f696d706c2f4f726967696e547970653b4c000975726c4f724e756c6c71007e00087870ff" +
"ffffffffffffff7074000b66616b65206f726967696e7e720023636f6d2e74797065736166652e63" +
"6f6e6669672e696d706c2e4f726967696e5479706500000000000000001200007872000e6a617661" +
"2e6c616e672e456e756d0000000000000000120000787074000747454e455249437073720025636f" +
"6d2e74797065736166652e636f6e6669672e696d706c2e53696d706c65436f6e6669670000000000" +
"0000010200014c00066f626a65637474002f4c636f6d2f74797065736166652f636f6e6669672f69" +
"6d706c2f4162737472616374436f6e6669674f626a6563743b787071007e000600737200146a6176" +
"612e7574696c2e4c696e6b65644c6973740c29535d4a60882203000078707704000000037372002b" +
"636f6d2e74797065736166652e636f6e6669672e696d706c2e53696d706c65436f6e6669674f626a" +
"65637400000000000000010200035a001069676e6f72657346616c6c6261636b735a00087265736f" +
"6c7665644c000576616c756574000f4c6a6176612f7574696c2f4d61703b7871007e00027371007e" +
"0007ffffffffffffffff7074000c656d70747920636f6e66696771007e000e707371007e00107100" +
"7e001700017372001e6a6176612e7574696c2e436f6c6c656374696f6e7324456d7074794d617059" +
"3614855adce7d002000078707372002b636f6d2e74797065736166652e636f6e6669672e696d706c" +
"2e436f6e666967537562737469747574696f6e61f02fc05eca6d7d0200035a001069676e6f726573" +
"46616c6c6261636b7349000c7072656669784c656e6774684c000670696563657371007e00017871" +
"007e00047371007e0007ffffffffffffffff7071007e000b71007e000e7000000000007371007e00" +
"137704000000017372002f636f6d2e74797065736166652e636f6e6669672e696d706c2e53756273" +
"7469747574696f6e45787072657373696f6e00000000000000010200025a00086f7074696f6e616c" +
"4c00047061746874001f4c636f6d2f74797065736166652f636f6e6669672f696d706c2f50617468" +
"3b7870007372001d636f6d2e74797065736166652e636f6e6669672e696d706c2e50617468000000" +
"00000000010200024c0005666972737471007e00084c000972656d61696e64657271007e00227870" +
"740003666f6f70787371007e001d7371007e0007ffffffffffffffff7071007e000b71007e000e70" +
"00000000007371007e00137704000000017371007e0021007371007e0024740003626172707878"
val empty = SimpleConfigObject.empty()
val s1 = subst("foo")
val s2 = subst("bar")
val a = new ConfigDelayedMergeObject(fakeOrigin(), List[AbstractConfigValue](empty, s1, s2).asJava)
val b = checkSerializable(expectedSerialization, a)
}
@Test
def valuesToString() {
// just check that these don't throw, the exact output

View File

@ -13,6 +13,12 @@ import com.typesafe.config.Config
import com.typesafe.config.ConfigSyntax
import com.typesafe.config.ConfigFactory
import java.io.File
import java.io.ByteArrayOutputStream
import java.io.ObjectOutputStream
import java.io.ByteArrayInputStream
import java.io.ObjectInputStream
import org.apache.commons.codec.binary.Hex
import scala.annotation.tailrec
abstract trait TestUtils {
protected def intercept[E <: Throwable: Manifest](block: => Unit): E = {
@ -82,6 +88,92 @@ abstract trait TestUtils {
checkNotEqualToRandomOtherThing(b)
}
private def copyViaSerialize(o: java.io.Serializable): AnyRef = {
val byteStream = new ByteArrayOutputStream()
val objectStream = new ObjectOutputStream(byteStream)
objectStream.writeObject(o)
objectStream.close()
val inStream = new ByteArrayInputStream(byteStream.toByteArray())
val inObjectStream = new ObjectInputStream(inStream)
val copy = inObjectStream.readObject()
inObjectStream.close()
copy
}
protected def checkSerializationCompat[T: Manifest](expectedHex: String, o: T): Unit = {
// be sure we can still deserialize the old one
val inStream = new ByteArrayInputStream(Hex.decodeHex(expectedHex.toCharArray()))
val inObjectStream = new ObjectInputStream(inStream)
var failure: Option[Exception] = None
val deserialized = try {
inObjectStream.readObject()
} catch {
case e: Exception =>
failure = Some(e)
null
}
inObjectStream.close()
val why = failure.map({ e => ": " + e.getClass.getSimpleName + ": " + e.getMessage }).getOrElse("")
assertEquals("Can no longer deserialize the old format of " + o.getClass.getSimpleName + why,
o, deserialized)
assertFalse(failure.isDefined) // should have thrown if we had a failure
val byteStream = new ByteArrayOutputStream()
val objectStream = new ObjectOutputStream(byteStream)
objectStream.writeObject(o)
objectStream.close()
val hex = Hex.encodeHexString(byteStream.toByteArray())
if (expectedHex != hex) {
@tailrec
def outputStringLiteral(s: String): Unit = {
if (s.nonEmpty) {
val (head, tail) = s.splitAt(80)
val plus = if (tail.isEmpty) "" else " +"
System.err.println("\"" + head + "\"" + plus)
outputStringLiteral(tail)
}
}
System.err.println("Correct result literal for " + o.getClass.getSimpleName + " serialization:")
System.err.println("\"\" + ") // line up all the lines by using empty string on first line
outputStringLiteral(hex)
}
assertEquals(o.getClass.getSimpleName + " serialization has changed (though we still deserialized the old serialization)", expectedHex, hex)
}
protected def checkSerializable[T: Manifest](expectedHex: String, o: T): T = {
val t = checkSerializable(o)
checkSerializationCompat(expectedHex, o)
t
}
protected def checkSerializable[T: Manifest](o: T): T = {
checkEqualObjects(o, o)
assertTrue(o.getClass.getSimpleName + " not an instance of Serializable", o.isInstanceOf[java.io.Serializable])
val a = o.asInstanceOf[java.io.Serializable]
val b = try {
copyViaSerialize(a)
} catch {
case nf: ClassNotFoundException =>
throw new AssertionError("failed to make a copy via serialization, " +
"possibly caused by http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6446627",
nf)
case e: Exception =>
throw new AssertionError("failed to make a copy via serialization", e)
}
assertTrue("deserialized type " + b.getClass.getSimpleName + " doesn't match serialized type " + a.getClass.getSimpleName,
manifest[T].erasure.isAssignableFrom(b.getClass))
checkEqualObjects(a, b)
b.asInstanceOf[T]
}
def fakeOrigin() = {
SimpleConfigOrigin.newSimple("fake origin")
}
@ -372,7 +464,7 @@ abstract trait TestUtils {
protected def substInString(ref: String, optional: Boolean): ConfigSubstitution = {
import scala.collection.JavaConverters._
val path = Path.newPath(ref)
val pieces = List("start<", new SubstitutionExpression(path, optional), ">end")
val pieces = List[AnyRef]("start<", new SubstitutionExpression(path, optional), ">end")
new ConfigSubstitution(fakeOrigin(), pieces.asJava)
}