use of org.apache.geode.InvalidDeltaException in project geode by apache.
the class PutMessage method toData.
/*
* @Override public String toString() { StringBuilder buff = new StringBuilder(super.toString());
* buff.append("; has old value="+this.hasOldValue);
* buff.append("; isOldValueSerialized ="+this.oldValueIsSerialized);
* buff.append("; oldvalue bytes="+this.oldValBytes);
* buff.append("; oldvalue object="+this.oldValObj); buff.toString(); return buff.toString(); }
*/
@Override
public void toData(DataOutput out) throws IOException {
PartitionedRegion region = null;
try {
boolean flag = internalDs.getConfig().getDeltaPropagation();
if (this.event.getDeltaBytes() != null && flag && this.sendDelta) {
this.hasDelta = true;
} else {
// Reset the flag when sending full object.
this.hasDelta = false;
}
} catch (RuntimeException re) {
throw new InvalidDeltaException(re);
}
super.toData(out);
int extraFlags = this.deserializationPolicy;
if (this.bridgeContext != null)
extraFlags |= HAS_BRIDGE_CONTEXT;
if (this.deserializationPolicy != DistributedCacheOperation.DESERIALIZATION_POLICY_NONE && (this.valObj != null || getValBytes() != null) && this.sendDeltaWithFullValue && this.event.getDeltaBytes() != null) {
extraFlags |= HAS_DELTA_WITH_FULL_VALUE;
}
if (this.originalSender != null)
extraFlags |= HAS_ORIGINAL_SENDER;
out.writeByte(extraFlags);
DataSerializer.writeObject(getKey(), out);
DataSerializer.writeObject(getCallbackArg(), out);
out.writeLong(this.lastModified);
out.writeByte(this.op.ordinal);
if (this.bridgeContext != null) {
DataSerializer.writeObject(this.bridgeContext, out);
}
if (this.originalSender != null) {
DataSerializer.writeObject(this.originalSender, out);
}
InternalDataSerializer.invokeToData(this.eventId, out);
if (this.expectedOldValue != null) {
DataSerializer.writeObject(this.expectedOldValue, out);
}
if (this.hasFilterInfo) {
InternalDataSerializer.invokeToData(this.filterInfo, out);
}
if (this.hasDelta) {
try {
region = PartitionedRegion.getPRFromId(this.regionId);
} catch (PRLocallyDestroyedException e) {
throw new IOException("Delta can not be extracted as region is locally destroyed");
}
DataSerializer.writeByteArray(this.event.getDeltaBytes(), out);
region.getCachePerfStats().incDeltasSent();
} else {
DistributedCacheOperation.writeValue(this.deserializationPolicy, this.valObj, getValBytes(), out);
if ((extraFlags & HAS_DELTA_WITH_FULL_VALUE) != 0) {
DataSerializer.writeByteArray(this.event.getDeltaBytes(), out);
}
}
if (this.versionTag != null) {
DataSerializer.writeObject(this.versionTag, out);
}
}
use of org.apache.geode.InvalidDeltaException in project geode by apache.
the class DeltaSession method fromDelta.
public void fromDelta(DataInput in) throws IOException, InvalidDeltaException {
// Read whether to apply the changes to another DS if necessary
this.applyRemotely = in.readBoolean();
// Read the events
List<DeltaSessionAttributeEvent> events = null;
try {
events = DataSerializer.readArrayList(in);
} catch (ClassNotFoundException e) {
throw new InvalidDeltaException(e);
}
// This allows for backwards compatibility with 2.1 clients
if (((InputStream) in).available() > 0) {
this.lastAccessedTime = in.readLong();
this.maxInactiveInterval = in.readInt();
}
// Iterate and apply the events
for (DeltaSessionAttributeEvent event : events) {
event.apply(this);
}
// Add the events to the gateway delta region if necessary
if (this.enableGatewayDeltaReplication && this.applyRemotely) {
setCurrentGatewayDeltaEvent(new DeltaSessionAttributeEventBatch(this.sessionRegionName, this.id, events));
}
// Access it to set the last accessed time. End access it to set not new.
access();
endAccess();
}
use of org.apache.geode.InvalidDeltaException in project geode by apache.
the class DeltaSession8 method fromDelta.
public void fromDelta(DataInput in) throws IOException, InvalidDeltaException {
// Read whether to apply the changes to another DS if necessary
this.applyRemotely = in.readBoolean();
// Read the events
List<DeltaSessionAttributeEvent> events = null;
try {
events = DataSerializer.readArrayList(in);
} catch (ClassNotFoundException e) {
throw new InvalidDeltaException(e);
}
// This allows for backwards compatibility with 2.1 clients
if (((InputStream) in).available() > 0) {
this.lastAccessedTime = in.readLong();
this.maxInactiveInterval = in.readInt();
}
// Iterate and apply the events
for (DeltaSessionAttributeEvent event : events) {
event.apply(this);
}
// Add the events to the gateway delta region if necessary
if (this.enableGatewayDeltaReplication && this.applyRemotely) {
setCurrentGatewayDeltaEvent(new DeltaSessionAttributeEventBatch(this.sessionRegionName, this.id, events));
}
// Access it to set the last accessed time. End access it to set not new.
access();
endAccess();
}
use of org.apache.geode.InvalidDeltaException in project geode by apache.
the class DeltaPropagationStatsDUnitTest method putErrorDeltaForSender.
public static void putErrorDeltaForSender(Integer keys, Long updates, Long errors, Boolean doCreate) {
Region r = cache.getRegion(REGION_NAME);
assertTrue("Errors cannot be more than 1/3rd of total updates", (keys * updates) / 3 > errors);
if (doCreate) {
for (int i = 0; i < keys; i++) {
r.create(DELTA_KEY + i, new DeltaTestImpl());
}
}
for (int i = 0; i < keys; i++) {
for (long j = 0; j < updates; j++) {
DeltaTestImpl delta = new DeltaTestImpl();
if (j % 3 == 1) {
delta.setStr("one");
} else if (j % 3 == 2) {
delta.setIntVar(111);
if (errors != 0) {
delta.setIntVar(DeltaTestImpl.ERRONEOUS_INT_FOR_TO_DELTA);
errors--;
}
} else {
delta.setByteArr(new byte[] { 11, 22, 33, 44 });
delta.setDoubleVar(5.7);
}
try {
r.put(DELTA_KEY + i, delta);
assertTrue("Expected an InvalidDeltaException to be thrown, but it wasn't!", delta.getIntVar() != DeltaTestImpl.ERRONEOUS_INT_FOR_TO_DELTA);
} catch (InvalidDeltaException ide) {
assertTrue("InvalidDeltaException not expected.", delta.getIntVar() == DeltaTestImpl.ERRONEOUS_INT_FOR_TO_DELTA);
cache.getLoggerI18n().fine("Recieved InvalidDeltaException as expected.");
}
}
}
assertTrue("Error puts not exhausted", errors == 0);
}
use of org.apache.geode.InvalidDeltaException in project geode by apache.
the class DeltaPropagationDUnitTest method updateDelta.
public static void updateDelta() {
try {
Region r = cache.getRegion("/" + regionName);
assertNotNull(r);
for (int i = 1; i < EVENTS_SIZE; i++) {
try {
r.put(DELTA_KEY, deltaPut[i]);
} catch (InvalidDeltaException ide) {
assertTrue("InvalidDeltaException not expected for deltaPut[" + i + "]", deltaPut[i].getIntVar() == DeltaTestImpl.ERRONEOUS_INT_FOR_TO_DELTA);
}
}
r.put(LAST_KEY, "");
} catch (Exception ex) {
org.apache.geode.test.dunit.Assert.fail("failed in updateDelta()", ex);
}
}
Aggregations