Package com.esotericsoftware.kryo

Examples of com.esotericsoftware.kryo.Kryo$ClassReferences


public class SerializeUtilTest {
 
 
  @Test
  public void test_measurepoint_save(){
    Kryo kryo = SerializeUtil.createKryo();
    Output output = new Output(66666);
   
    kryo.writeClassAndObject(output, new MeasurePointData("1111"));
    int oldPos = output.position();
    kryo.writeClassAndObject(output, new MeasurePointData("1111"));
    assertEquals(oldPos+19,output.position());//only key is written not string again
    kryo.writeClassAndObject(output, new MeasurePointData("1111"));
    kryo.writeClassAndObject(output, new MeasurePointData("2222"));
    kryo.writeClassAndObject(output, new MeasurePointData("2222"));
    kryo.writeClassAndObject(output, new MeasurePointData("1111"));
   
    Input input = new Input(output.getBuffer());
    assertEquals("1111", ((MeasurePointData)kryo.readClassAndObject(input)).getMeasurePointId());
    assertEquals("1111", ((MeasurePointData)kryo.readClassAndObject(input)).getMeasurePointId());
    assertEquals("1111", ((MeasurePointData)kryo.readClassAndObject(input)).getMeasurePointId());
    assertEquals("2222", ((MeasurePointData)kryo.readClassAndObject(input)).getMeasurePointId());
    assertEquals("2222", ((MeasurePointData)kryo.readClassAndObject(input)).getMeasurePointId());
    assertEquals("1111", ((MeasurePointData)kryo.readClassAndObject(input)).getMeasurePointId());
  }
View Full Code Here


  }
 
 
  @Test
  public void test_write(){
    Kryo kryo = Mockito.mock(Kryo.class);
    Output output = Mockito.mock(Output.class);
   
    MeasurePointIdSerializer measurePointIdSerializer = new MeasurePointIdSerializer();
    measurePointIdSerializer.write(kryo, output, "111");
    Mockito.verify(output).writeInt(-1);
View Full Code Here

    Mockito.verify(output,Mockito.never()).writeString("111");
  }
 
  @Test
  public void test_read(){
    Kryo kryo = Mockito.mock(Kryo.class);
    Input input = Mockito.mock(Input.class);
 
    Mockito.when(input.readString()).thenReturn("111");
    Mockito.when(input.readInt()).thenReturn(-1);
    MeasurePointIdSerializer measurePointIdSerializer = new MeasurePointIdSerializer();
View Full Code Here

    long latest = Long.MIN_VALUE;
    for (MonitoringData d : values) {
      earliest = Math.min(d.getTimeStamp().getTime(), earliest);
      latest = Math.max(d.getTimeStamp().getTime(), latest);
    }
    Kryo kryo = SerializeUtil.createKryo();
    b.position(MonitoringDataStorage.FIRST_RECORD_POSITION);
    Output output = new Output(new ByteBufferOutputStream(b));
    for (MonitoringData data : values) {
      kryo.writeClassAndObject(output, data);
    }
    output.close();
    int limit = b.position();
   
    b.putLong(MonitoringDataStorage.EARLIEST_POSITION, earliest);
View Full Code Here

    long earliestTimestamp = b.getLong(MonitoringDataStorage.EARLIEST_POSITION);
    long latestTimestamp = b.getLong(MonitoringDataStorage.LATEST_POSITION);
    assertEquals(42, earliestTimestamp);
    assertEquals(43, latestTimestamp);
   
    Kryo kryo = new Kryo();
    Input input = new Input(new ByteBufferInputStream(b));
    input.setPosition(MonitoringDataStorage.FIRST_RECORD_POSITION);
    assertEquals("blabla1",((MonitoringDataDummy)kryo.readClassAndObject(input)).value);
    assertEquals("blabla2",((MonitoringDataDummy)kryo.readClassAndObject(input)).value);
    assertNull(kryo.readClassAndObject(input));
    b.putInt(MonitoringDataStorage.LIMIT_POSITION, b.position());
    b.position(0);
    ranAccess.close();
    }
View Full Code Here

    public TemporaryFolder testFolder = new TemporaryFolder();
 
 
  @Test
  public void test_kryo(){
    Kryo kryo = new Kryo();
    kryo.register(AdapterWfLaunchInfo.class);
    {
      Output output = new Output(1024);
      final AdapterWfLaunchInfo object = new AdapterWfLaunchInfo();
      object.setAdapterName("abc");
      kryo.writeClassAndObject(output, object);
      kryo.writeClassAndObject(output, new LogEvent());
      assertTrue(output.getBuffer().length>0);
     
      Input input = new Input(output.getBuffer());
      assertEquals(AdapterWfLaunchInfo.class, kryo.readClassAndObject(input).getClass());
      assertEquals(LogEvent.class, kryo.readClassAndObject(input).getClass());
    }
  }
View Full Code Here

    NetworkKryoInit newInit = new NetworkKryoInit();
    newInit.registerKryo(client.getKryo());
    client.addListener(this);

    serializer = new Kryo();
    init.registerKryo(serializer);
    factory = new ChunkSendFactory(serializer);
  }
View Full Code Here

    NetworkKryoInit newInit = new NetworkKryoInit();
    newInit.registerKryo(client.getKryo());

    client.addListener(this);

    serializer = new Kryo();
    init.registerKryo(serializer);
    factory = new ChunkSendFactory(serializer);
  }
View Full Code Here

         *
         * @return create Kryo instance
         */
        protected Kryo createInstance()
        {
            Kryo kryo = new Kryo();
            kryo.setReferences(false);
            return kryo;
        }
View Full Code Here

public class NetworkMessages
{
  static public void registerBuiltInMessages(EndPoint endpoint)
  {
    Kryo k = endpoint.getKryo();

    k.register(Login.class);

    k.register(Disconnect.class);
    k.register(Disconnect.Reason.class);

    k.register(UserConnect.class);
    k.register(UserDisconnect.class);
    k.register(ChatMessage.class);
    k.register(UserList.class);

    k.register(CreateNode.class);
    k.register(DestroyNode.class);

    k.register(FloatReplicator.Message.class);
    k.register(IntReplicator.Message.class);
    k.register(Vector2fReplicator.Message.class);
    k.register(Vector2iReplicator.Message.class);
  }
View Full Code Here

TOP

Related Classes of com.esotericsoftware.kryo.Kryo$ClassReferences

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.