Search in sources :

Example 1 with ObjectMarshallingStrategyStoreImpl

use of org.drools.serialization.protobuf.marshalling.ObjectMarshallingStrategyStoreImpl in project drools by kiegroup.

the class FactHandleMarshallingTest method backwardsCompatibleEventFactHandleTest.

@Test
public void backwardsCompatibleEventFactHandleTest() throws IOException, ClassNotFoundException {
    InternalKnowledgeBase kBase = createKnowledgeBase();
    StatefulKnowledgeSessionImpl wm = createWorkingMemory(kBase);
    InternalFactHandle factHandle = createEventFactHandle(wm, kBase);
    // marshall/serialize workItem
    byte[] byteArray;
    {
        ObjectMarshallingStrategy[] strats = new ObjectMarshallingStrategy[] { MarshallerFactory.newSerializeMarshallingStrategy(), new MarshallerProviderImpl().newIdentityMarshallingStrategy() };
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ProtobufMarshallerWriteContext outContext = new ProtobufMarshallerWriteContext(baos, null, null, null, new ObjectMarshallingStrategyStoreImpl(strats), true, true, null);
        OldOutputMarshallerMethods.writeFactHandle_v1(outContext, (ObjectOutputStream) outContext, outContext.getObjectMarshallingStrategyStore(), 2, factHandle);
        outContext.close();
        byteArray = baos.toByteArray();
    }
    // unmarshall/deserialize workItem
    InternalFactHandle newFactHandle;
    {
        // Only put serialization strategy in
        ObjectMarshallingStrategy[] newStrats = new ObjectMarshallingStrategy[] { MarshallerFactory.newSerializeMarshallingStrategy() };
        ByteArrayInputStream bais = new ByteArrayInputStream(byteArray);
        ProtobufMarshallerReaderContext inContext = new ProtobufMarshallerReaderContext(bais, null, null, new ObjectMarshallingStrategyStoreImpl(newStrats), Collections.EMPTY_MAP, true, true, null);
        inContext.setWorkingMemory(wm);
        newFactHandle = InputMarshaller.readFactHandle(inContext);
        inContext.close();
    }
    assertTrue("Serialized FactHandle not the same as the original.", compareInstances(factHandle, newFactHandle));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StatefulKnowledgeSessionImpl(org.drools.kiesession.session.StatefulKnowledgeSessionImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) InternalFactHandle(org.drools.core.common.InternalFactHandle) ObjectOutputStream(java.io.ObjectOutputStream) InternalKnowledgeBase(org.drools.kiesession.rulebase.InternalKnowledgeBase) ObjectMarshallingStrategyStoreImpl(org.drools.serialization.protobuf.marshalling.ObjectMarshallingStrategyStoreImpl) Test(org.junit.Test)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 InternalFactHandle (org.drools.core.common.InternalFactHandle)1 InternalKnowledgeBase (org.drools.kiesession.rulebase.InternalKnowledgeBase)1 StatefulKnowledgeSessionImpl (org.drools.kiesession.session.StatefulKnowledgeSessionImpl)1 ObjectMarshallingStrategyStoreImpl (org.drools.serialization.protobuf.marshalling.ObjectMarshallingStrategyStoreImpl)1 Test (org.junit.Test)1