use of org.apache.geode.DeltaTestImpl in project geode by apache.
the class P2PDeltaPropagationDUnitTest method getOnDeltaEnabledServer.
public static void getOnDeltaEnabledServer() throws Exception {
Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME);
assertTrue(((DeltaTestImpl) r1.getEntry("KEY").getValue()).getIntVar() == NEW_INT);
assertTrue(((DeltaTestImpl) r1.getEntry("KEY").getValue()).getStr().equals(NEW_STR));
}
use of org.apache.geode.DeltaTestImpl in project geode by apache.
the class P2PDeltaPropagationDUnitTest method checkForNoFullObjectResend.
public static void checkForNoFullObjectResend() throws Exception {
Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME);
assertNull(((DeltaTestImpl) r1.getEntry("KEY").getValue()));
}
use of org.apache.geode.DeltaTestImpl in project geode by apache.
the class PdxSerializableJUnitTest method testByteFormatForDSInsidePDX.
@Test
public void testByteFormatForDSInsidePDX() throws Exception {
String myString1 = "ComplexClass1_myString1";
long myLong = 15654;
DataSerializable myDS = new DeltaTestImpl(100, "value");
String myString2 = "ComplexClass1_myString2";
float myFloat = 123.023f;
HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT);
PdxSerializable pdx = new DSInsidePdx(myString1, myLong, myDS, myString2, myFloat);
DataSerializer.writeObject(pdx, out);
int typeId = getPdxTypeIdForClass(DSInsidePdx.class);
HeapDataOutputStream hdos1 = new HeapDataOutputStream(Version.CURRENT);
DataSerializer.writeString(myString1, hdos1);
byte[] str1Bytes = hdos1.toByteArray();
System.out.println("Length of string1: " + str1Bytes.length);
HeapDataOutputStream hdos2 = new HeapDataOutputStream(Version.CURRENT);
DataSerializer.writeObject(myDS, hdos2);
byte[] dsBytes = hdos2.toByteArray();
System.out.println("Length of DS: " + dsBytes.length);
HeapDataOutputStream hdos3 = new HeapDataOutputStream(Version.CURRENT);
DataSerializer.writeString(myString2, hdos3);
byte[] str2Bytes = hdos3.toByteArray();
System.out.println("Length of string2: " + str2Bytes.length);
int length = str1Bytes.length + 8 + /* myLong */
dsBytes.length + str2Bytes.length + 4 + /* myFloat */
(2 * 2);
int offset1 = 0;
int offset2 = offset1 + 8 + str1Bytes.length;
int offset3 = offset1 + 8 + str1Bytes.length + dsBytes.length;
byte[] actual = out.toByteArray();
int floatBytes = Float.floatToRawIntBits(myFloat);
Byte[] expected = new Byte[] { // byte
DSCODE.PDX, // int -
(byte) (length >> 24), // int -
(byte) (length >> 16), // int -
(byte) (length >> 8), // int -
(byte) length, // int -
(byte) (typeId >> 24), // int -
(byte) (typeId >> 16), // int -
(byte) (typeId >> 8), // int -
(byte) typeId, // typeId
(byte) (myLong >> 56), (byte) (myLong >> 48), (byte) (myLong >> 40), (byte) (myLong >> 32), // long -
(byte) (myLong >> 24), // long -
(byte) (myLong >> 16), // long -
(byte) (myLong >> 8), // long -
(byte) myLong, // myLong
(byte) (floatBytes >> 24), (byte) (floatBytes >> 16), (byte) (floatBytes >> 8), // float - myFloat
(byte) floatBytes, // offset of myString2
(byte) (offset3 >> 8), // offset of myString2
(byte) offset3, // offset of myHashMap
(byte) (offset2 >> 8), // offset of myHashMap
(byte) offset2 };
for (int i = (str1Bytes.length - 1); i >= 0; i--) {
expected = // +
(Byte[]) ArrayUtils.insert(expected, offset1 + PdxWriterImpl.HEADER_SIZE, str1Bytes[i]);
// 5
// for:
// 1
// for
// DSCODE.PDX
// and
// 4
// for
// byte
// stream
// length
}
for (int i = (dsBytes.length - 1); i >= 0; i--) {
expected = (Byte[]) ArrayUtils.insert(expected, offset2 + PdxWriterImpl.HEADER_SIZE, dsBytes[i]);
}
for (int i = (str2Bytes.length - 1); i >= 0; i--) {
expected = (Byte[]) ArrayUtils.insert(expected, offset3 + PdxWriterImpl.HEADER_SIZE, str2Bytes[i]);
}
StringBuffer msg = new StringBuffer("Actual output: ");
for (byte val : actual) {
msg.append(val + ", ");
}
msg.append("\nExpected output: ");
for (byte val : expected) {
msg.append(val + ", ");
}
assertTrue("Mismatch in length, actual.length: " + actual.length + " and expected length: " + expected.length, actual.length == expected.length);
for (int i = 0; i < actual.length; i++) {
if (actual[i] != expected[i]) {
System.out.println(msg.toString());
}
assertTrue("Mismatch at index " + i, actual[i] == expected[i]);
}
System.out.println("\n");
DataInput in = new DataInputStream(new ByteArrayInputStream(actual));
DSInsidePdx actualVal = (DSInsidePdx) DataSerializer.readObject(in);
// System.out.println("actualVal..."+actualVal);
assertTrue("Mismatch in write and read value: Value Write..." + pdx + " Value Read..." + actualVal, pdx.equals(actualVal));
System.out.println("\n");
}
use of org.apache.geode.DeltaTestImpl in project geode by apache.
the class DeltaPropagationDUnitTest method createDeltas.
public static void createDeltas() {
try {
Region r = cache.getRegion("/" + regionName);
assertNotNull(r);
for (int i = 0; i < 100; i++) {
r.create(DELTA_KEY + i, new DeltaTestImpl());
}
r.create(LAST_KEY, "");
} catch (Exception ex) {
org.apache.geode.test.dunit.Assert.fail("failed in createDeltas()", ex);
}
}
use of org.apache.geode.DeltaTestImpl in project geode by apache.
the class DeltaPropagationDUnitTest method prepareErroneousDeltasForToDelta.
public static void prepareErroneousDeltasForToDelta() {
for (int i = 0; i < EVENTS_SIZE; i++) {
deltaPut[i] = new DeltaTestImpl(0, "0", new Double(0), new byte[0], new TestObject1("0", 0));
}
deltaPut[1].setIntVar(5);
deltaPut[2].setIntVar(5);
deltaPut[3].setIntVar(DeltaTestImpl.ERRONEOUS_INT_FOR_TO_DELTA);
deltaPut[4].setIntVar(5);
deltaPut[5].setIntVar(5);
deltaPut[2].setByteArr(new byte[] { 1, 2, 3, 4, 5 });
deltaPut[3].setByteArr(new byte[] { 1, 2, 3, 4, 5 });
deltaPut[4].setByteArr(new byte[] { 1, 2, 3, 4, 5 });
deltaPut[5].setByteArr(new byte[] { 1, 2, 3, 4, 5 });
deltaPut[3].setDoubleVar(new Double(5));
deltaPut[4].setDoubleVar(new Double(5));
deltaPut[5].setDoubleVar(new Double(5));
deltaPut[4].setStr("str changed");
deltaPut[5].setStr("str changed");
deltaPut[5].setIntVar(100);
deltaPut[5].setTestObj(new TestObject1("CHANGED", 100));
}
Aggregations