Merge "Initialize PatchList with minimal values for serialization"
This commit is contained in:
@@ -105,8 +105,6 @@ public class PatchList implements Serializable {
|
|||||||
this.patches = patches;
|
this.patches = patches;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PatchList() {}
|
|
||||||
|
|
||||||
/** Old side tree or commit; null only if this is a combined diff. */
|
/** Old side tree or commit; null only if this is a combined diff. */
|
||||||
@Nullable
|
@Nullable
|
||||||
public ObjectId getOldId() {
|
public ObjectId getOldId() {
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import static com.google.gerrit.server.patch.DiffSummaryLoader.toDiffSummary;
|
|||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.cache.Cache;
|
import com.google.common.cache.Cache;
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import com.google.common.util.concurrent.UncheckedExecutionException;
|
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||||
import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace;
|
import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
@@ -31,7 +30,6 @@ import com.google.inject.Inject;
|
|||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import com.google.inject.name.Named;
|
import com.google.inject.name.Named;
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import org.eclipse.jgit.errors.LargeObjectException;
|
import org.eclipse.jgit.errors.LargeObjectException;
|
||||||
import org.eclipse.jgit.lib.Config;
|
import org.eclipse.jgit.lib.Config;
|
||||||
@@ -198,15 +196,11 @@ public class PatchListCacheImpl implements PatchListCache {
|
|||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public LargeObjectTombstone() {}
|
public LargeObjectTombstone() {
|
||||||
|
// Initialize super class with valid values. We don't care about the inner state, but need to
|
||||||
/**
|
// pass valid values that don't break (de)serialization.
|
||||||
* Return an empty list to prevent {@link NullPointerException}s inside of {@link
|
super(
|
||||||
* PatchListWeigher}.
|
null, ObjectId.zeroId(), false, ComparisonType.againstAutoMerge(), new PatchListEntry[0]);
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<PatchListEntry> getPatches() {
|
|
||||||
return ImmutableList.of();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,11 @@ package com.google.gerrit.server.patch;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import com.google.gerrit.reviewdb.client.Patch;
|
import com.google.gerrit.reviewdb.client.Patch;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -65,4 +70,21 @@ public class PatchListTest {
|
|||||||
});
|
});
|
||||||
assertThat(names).isEqualTo(want);
|
assertThat(names).isEqualTo(want);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void largeObjectTombstoneCanBeSerializedAndDeserialized() throws Exception {
|
||||||
|
// Serialize
|
||||||
|
byte[] serializedObject;
|
||||||
|
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
ObjectOutputStream objectStream = new ObjectOutputStream(baos)) {
|
||||||
|
objectStream.writeObject(new PatchListCacheImpl.LargeObjectTombstone());
|
||||||
|
serializedObject = baos.toByteArray();
|
||||||
|
assertThat(serializedObject).isNotNull();
|
||||||
|
}
|
||||||
|
// Deserialize
|
||||||
|
try (InputStream is = new ByteArrayInputStream(serializedObject);
|
||||||
|
ObjectInputStream ois = new ObjectInputStream(is)) {
|
||||||
|
assertThat(ois.readObject()).isInstanceOf(PatchListCacheImpl.LargeObjectTombstone.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user