/* * Copyright (C) 2014 The Calrissian Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.calrissian.flowmix.api.kryo; import com.esotericsoftware.kryo.Kryo; import com.esotericsoftware.kryo.io.Input; import com.esotericsoftware.kryo.io.Output; import org.calrissian.mango.domain.event.BaseEvent; import org.calrissian.mango.domain.event.Event; import org.calrissian.mango.domain.Tuple; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.UUID; import static java.lang.System.currentTimeMillis; import static org.junit.Assert.assertEquals; public class EventSerializerTest { @Test public void test() { Kryo kryo = new Kryo(); kryo.register(BaseEvent.class, new EventSerializer()); Event event = new BaseEvent(UUID.randomUUID().toString(), currentTimeMillis()); event.put(new Tuple("key1", "value1")); event.put(new Tuple("key2", "value2")); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Output output = new Output(baos); kryo.writeClassAndObject(output, event); output.flush(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); Input input = new Input(bais); Event actualEvent = (Event) kryo.readClassAndObject(input); assertEquals(event, actualEvent); } }