Commit 385adc5f by Harish Butani

fix tests to use a dateformat w/o timeZone

parent 3291e928
...@@ -31,8 +31,8 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -31,8 +31,8 @@ import java.util.concurrent.atomic.AtomicInteger;
public class MemRepository implements IRepository { public class MemRepository implements IRepository {
private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
private static SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); public static SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd");
final TypeSystem typeSystem; final TypeSystem typeSystem;
/* /*
......
...@@ -401,6 +401,12 @@ public class DataTypes { ...@@ -401,6 +401,12 @@ public class DataTypes {
return convertNull(m); return convertNull(m);
} }
@Override
public void output(Date val, Appendable buf, String prefix) throws MetadataException {
TypeUtils.outputVal(val == null ? "<null>" :
MetadataService.getCurrentRepository().getDateFormat().format(val), buf, prefix);
}
public Date nullValue() { public Date nullValue() {
return null; return null;
} }
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
package org.apache.hadoop.metadata package org.apache.hadoop.metadata
import java.text.SimpleDateFormat
import org.apache.hadoop.metadata.json.{BigIntegerSerializer, BigDecimalSerializer, TypedStructSerializer, Serialization} import org.apache.hadoop.metadata.json.{BigIntegerSerializer, BigDecimalSerializer, TypedStructSerializer, Serialization}
import org.apache.hadoop.metadata.storage.StructInstance import org.apache.hadoop.metadata.storage.StructInstance
import org.apache.hadoop.metadata.types._ import org.apache.hadoop.metadata.types._
...@@ -31,7 +33,12 @@ import scala.language.implicitConversions ...@@ -31,7 +33,12 @@ import scala.language.implicitConversions
package object dsl { package object dsl {
implicit val formats = org.json4s.native.Serialization.formats(NoTypeHints) + new TypedStructSerializer + val defFormat = new DefaultFormats {
override protected def dateFormatter = new SimpleDateFormat("yyyy-MM-dd")
override val typeHints = NoTypeHints
}
implicit val formats = defFormat + new TypedStructSerializer +
new BigDecimalSerializer + new BigIntegerSerializer new BigDecimalSerializer + new BigIntegerSerializer
def service = MetadataService.getCurrentService def service = MetadataService.getCurrentService
......
...@@ -150,7 +150,7 @@ public class EnumTest extends BaseTest { ...@@ -150,7 +150,7 @@ public class EnumTest extends BaseTest {
"\tj : \t1\n" + "\tj : \t1\n" +
"\tk : \t1\n" + "\tk : \t1\n" +
"\tenum3 : \tCOMMITTED\n" + "\tenum3 : \tCOMMITTED\n" +
"\tl : \tWed Dec 10 18:35:58 PST 2014\n" + "\tl : \t2014-12-10\n" +
"\tm : \t[1, 1]\n" + "\tm : \t[1, 1]\n" +
"\tn : \t[1.1, 1.1]\n" + "\tn : \t[1.1, 1.1]\n" +
"\to : \t{b=2.0, a=1.0}\n" + "\to : \t{b=2.0, a=1.0}\n" +
...@@ -182,7 +182,7 @@ public class EnumTest extends BaseTest { ...@@ -182,7 +182,7 @@ public class EnumTest extends BaseTest {
"\tj : \t1\n" + "\tj : \t1\n" +
"\tk : \t1\n" + "\tk : \t1\n" +
"\tenum3 : \tCOMMITTED\n" + "\tenum3 : \tCOMMITTED\n" +
"\tl : \tWed Dec 10 18:35:58 PST 2014\n" + "\tl : \t2014-12-10\n" +
"\tm : \t[1, 1]\n" + "\tm : \t[1, 1]\n" +
"\tn : \t[1.1, 1.1]\n" + "\tn : \t[1.1, 1.1]\n" +
"\to : \t{b=2.0, a=1.0}\n" + "\to : \t{b=2.0, a=1.0}\n" +
...@@ -219,7 +219,7 @@ public class EnumTest extends BaseTest { ...@@ -219,7 +219,7 @@ public class EnumTest extends BaseTest {
"\tj : \t1\n" + "\tj : \t1\n" +
"\tk : \t1\n" + "\tk : \t1\n" +
"\tenum3 : \tCOMMITTED\n" + "\tenum3 : \tCOMMITTED\n" +
"\tl : \tWed Dec 10 18:35:58 PST 2014\n" + "\tl : \t2014-12-10\n" +
"\tm : \t[1, 1]\n" + "\tm : \t[1, 1]\n" +
"\tn : \t[1.1, 1.1]\n" + "\tn : \t[1.1, 1.1]\n" +
"\to : \t{b=2.0, a=1.0}\n" + "\to : \t{b=2.0, a=1.0}\n" +
...@@ -259,7 +259,7 @@ public class EnumTest extends BaseTest { ...@@ -259,7 +259,7 @@ public class EnumTest extends BaseTest {
"\tj : \t1\n" + "\tj : \t1\n" +
"\tk : \t1\n" + "\tk : \t1\n" +
"\tenum3 : \tCOMMITTED\n" + "\tenum3 : \tCOMMITTED\n" +
"\tl : \tThu Dec 11 00:00:00 PST 2014\n" + "\tl : \t2014-12-11\n" +
"\tm : \t[1, 1]\n" + "\tm : \t[1, 1]\n" +
"\tn : \t[1.100000000000000088817841970012523233890533447265625, 1" + "\tn : \t[1.100000000000000088817841970012523233890533447265625, 1" +
".100000000000000088817841970012523233890533447265625]\n" + ".100000000000000088817841970012523233890533447265625]\n" +
......
...@@ -52,7 +52,7 @@ public class StructTest extends BaseTest { ...@@ -52,7 +52,7 @@ public class StructTest extends BaseTest {
"\ti : \t1.0\n" + "\ti : \t1.0\n" +
"\tj : \t1\n" + "\tj : \t1\n" +
"\tk : \t1\n" + "\tk : \t1\n" +
"\tl : \tWed Dec 10 18:35:58 PST 2014\n" + "\tl : \t2014-12-10\n" +
"\tm : \t[1, 1]\n" + "\tm : \t[1, 1]\n" +
"\tn : \t[1.1, 1.1]\n" + "\tn : \t[1.1, 1.1]\n" +
"\to : \t{b=2.0, a=1.0}\n" + "\to : \t{b=2.0, a=1.0}\n" +
......
...@@ -94,7 +94,7 @@ class DSLTest extends BaseTest { ...@@ -94,7 +94,7 @@ class DSLTest extends BaseTest {
Assert.assertEquals(s"${i.o.asInstanceOf[java.util.Map[_,_]].keySet}", "[b, a]") Assert.assertEquals(s"${i.o.asInstanceOf[java.util.Map[_,_]].keySet}", "[b, a]")
// 5. Serialize mytype instance to Json // 5. Serialize mytype instance to Json
Assert.assertEquals(s"${pretty(render(i))}", "{\n \"$typeName$\":\"mytype\",\n \"e\":1,\n \"n\":[1,1.100000000000000088817841970012523233890533447265625],\n \"h\":1.0,\n \"b\":true,\n \"k\":1,\n \"j\":1,\n \"d\":2,\n \"m\":[1,1],\n \"g\":1,\n \"a\":1,\n \"i\":1.0,\n \"c\":1,\n \"l\":\"2014-12-03T08:00:00.000Z\",\n \"f\":1,\n \"o\":{\n \"b\":2.0,\n \"a\":1.0\n }\n}") Assert.assertEquals(s"${pretty(render(i))}", "{\n \"$typeName$\":\"mytype\",\n \"e\":1,\n \"n\":[1,1.100000000000000088817841970012523233890533447265625],\n \"h\":1.0,\n \"b\":true,\n \"k\":1,\n \"j\":1,\n \"d\":2,\n \"m\":[1,1],\n \"g\":1,\n \"a\":1,\n \"i\":1.0,\n \"c\":1,\n \"l\":\"2014-12-03\",\n \"f\":1,\n \"o\":{\n \"b\":2.0,\n \"a\":1.0\n }\n}")
} }
@Test def test2 { @Test def test2 {
......
...@@ -48,7 +48,7 @@ class SerializationTest extends BaseTest { ...@@ -48,7 +48,7 @@ class SerializationTest extends BaseTest {
val s: Struct = BaseTest.createStruct(ms) val s: Struct = BaseTest.createStruct(ms)
val ts: ITypedStruct = structType.convert(s, Multiplicity.REQUIRED) val ts: ITypedStruct = structType.convert(s, Multiplicity.REQUIRED)
Assert.assertEquals(ts.toString, "{\n\ta : \t1\n\tb : \ttrue\n\tc : \t1\n\td : \t2\n\te : \t1\n\tf : \t1\n\tg : \t1\n\th : \t1.0\n\ti : \t1.0\n\tj : \t1\n\tk : \t1\n\tl : \tWed Dec 10 18:35:58 PST 2014\n\tm : \t[1, 1]\n\tn : \t[1.1, 1.1]\n\to : \t{b=2.0, a=1.0}\n}") Assert.assertEquals(ts.toString, "{\n\ta : \t1\n\tb : \ttrue\n\tc : \t1\n\td : \t2\n\te : \t1\n\tf : \t1\n\tg : \t1\n\th : \t1.0\n\ti : \t1.0\n\tj : \t1\n\tk : \t1\n\tl : \t2014-12-10\n\tm : \t[1, 1]\n\tn : \t[1.1, 1.1]\n\to : \t{b=2.0, a=1.0}\n}")
implicit val formats = org.json4s.native.Serialization.formats(NoTypeHints) + new TypedStructSerializer + implicit val formats = org.json4s.native.Serialization.formats(NoTypeHints) + new TypedStructSerializer +
new BigDecimalSerializer + new BigIntegerSerializer new BigDecimalSerializer + new BigIntegerSerializer
...@@ -59,7 +59,7 @@ class SerializationTest extends BaseTest { ...@@ -59,7 +59,7 @@ class SerializationTest extends BaseTest {
// Typed Struct read back // Typed Struct read back
val ts1 = read[StructInstance](ser) val ts1 = read[StructInstance](ser)
Assert.assertEquals(ts1.toString, "{\n\ta : \t1\n\tb : \ttrue\n\tc : \t1\n\td : \t2\n\te : \t1\n\tf : \t1\n\tg : \t1\n\th : \t1.0\n\ti : \t1.0\n\tj : \t1\n\tk : \t1\n\tl : \tThu Dec 11 00:00:00 PST 2014\n\tm : \t[1, 1]\n\tn : \t[1.100000000000000088817841970012523233890533447265625, 1.100000000000000088817841970012523233890533447265625]\n\to : \t{b=2.0, a=1.0}\n}") Assert.assertEquals(ts1.toString, "{\n\ta : \t1\n\tb : \ttrue\n\tc : \t1\n\td : \t2\n\te : \t1\n\tf : \t1\n\tg : \t1\n\th : \t1.0\n\ti : \t1.0\n\tj : \t1\n\tk : \t1\n\tl : \t2014-12-11\n\tm : \t[1, 1]\n\tn : \t[1.100000000000000088817841970012523233890533447265625, 1.100000000000000088817841970012523233890533447265625]\n\to : \t{b=2.0, a=1.0}\n}")
} }
@Test def test2 { @Test def test2 {
...@@ -74,7 +74,7 @@ class SerializationTest extends BaseTest { ...@@ -74,7 +74,7 @@ class SerializationTest extends BaseTest {
{"$typeName$":"t1","e":1,"n":[1.1,1.1],"h":1.0,"b":true,"k":1,"j":1,"d":2,"m":[1,1],"g":1,"a":1,"i":1.0, {"$typeName$":"t1","e":1,"n":[1.1,1.1],"h":1.0,"b":true,"k":1,"j":1,"d":2,"m":[1,1],"g":1,"a":1,"i":1.0,
"c":1,"l":"2014-12-03T19:38:55.053Z","f":1,"o":{"b":2.0,"a":1.0}}""") "c":1,"l":"2014-12-03T19:38:55.053Z","f":1,"o":{"b":2.0,"a":1.0}}""")
// Typed Struct read from string // Typed Struct read from string
Assert.assertEquals(ts1.toString, "{\n\ta : \t1\n\tb : \ttrue\n\tc : \t1\n\td : \t2\n\te : \t1\n\tf : \t1\n\tg : \t1\n\th : \t1.0\n\ti : \t1.0\n\tj : \t1\n\tk : \t1\n\tl : \tWed Dec 03 00:00:00 PST 2014\n\tm : \t[1, 1]\n\tn : \t[1.100000000000000088817841970012523233890533447265625, 1.100000000000000088817841970012523233890533447265625]\n\to : \t{b=2.0, a=1.0}\n}") Assert.assertEquals(ts1.toString, "{\n\ta : \t1\n\tb : \ttrue\n\tc : \t1\n\td : \t2\n\te : \t1\n\tf : \t1\n\tg : \t1\n\th : \t1.0\n\ti : \t1.0\n\tj : \t1\n\tk : \t1\n\tl : \t2014-12-03\n\tm : \t[1, 1]\n\tn : \t[1.100000000000000088817841970012523233890533447265625, 1.100000000000000088817841970012523233890533447265625]\n\to : \t{b=2.0, a=1.0}\n}")
} }
@Test def testTrait { @Test def testTrait {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment