aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/skyframe
diff options
context:
space:
mode:
authorGravatar shahan <shahan@google.com>2018-02-20 13:20:30 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-20 13:22:33 -0800
commit80a0633bbeef3f84ab6eb6513a5d36936cd1bdbb (patch)
treea4ce5b4d8422a6103d0c93fb6ed8db3ccd1f1c22 /src/test/java/com/google/devtools/build/lib/skyframe
parentdd090a6e8825093e7e5364ed49f16ba68f0fe54c (diff)
Adds ObjectCodecRegistry to {Des|S}erializationContext.
* AutoCodec now delegates to the registry. * Adds getSuperclass logic for resolving a codec. * Small cleanups for classes that break the registry. TODO after this change: * Explicit CODEC definitions are no longer needed and existing ones should be cleaned up. * POLYMORPHIC is no longer be needed and should be cleaned up. PiperOrigin-RevId: 186351845
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/skyframe')
-rw-r--r--src/test/java/com/google/devtools/build/lib/skyframe/PackageValueTest.java92
-rw-r--r--src/test/java/com/google/devtools/build/lib/skyframe/serialization/ObjectCodecsTest.java3
2 files changed, 3 insertions, 92 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/PackageValueTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/PackageValueTest.java
deleted file mode 100644
index 38cbbf77e0..0000000000
--- a/src/test/java/com/google/devtools/build/lib/skyframe/PackageValueTest.java
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright 2018 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.lib.skyframe;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.devtools.build.lib.packages.Package;
-import com.google.devtools.build.lib.packages.PackageCodecDependencies;
-import com.google.devtools.build.lib.packages.PackageCodecDependencies.SimplePackageCodecDependencies;
-import com.google.devtools.build.lib.packages.PackageDeserializationException;
-import com.google.devtools.build.lib.packages.PackageDeserializerInterface;
-import com.google.devtools.build.lib.skyframe.serialization.DeserializationContext;
-import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec;
-import com.google.devtools.build.lib.skyframe.serialization.SerializationException;
-import com.google.protobuf.CodedInputStream;
-import java.io.IOException;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Basic tests for {@link PackageValue}. */
-@RunWith(JUnit4.class)
-public class PackageValueTest {
-
- private PackageDeserializerInterface mockDeserializer;
- private ObjectCodec<PackageValue> underTest;
- SimplePackageCodecDependencies codecDeps;
-
- @Before
- public void setUp() {
- this.mockDeserializer = mock(PackageDeserializerInterface.class);
- this.underTest = PackageValue.CODEC;
- this.codecDeps = new SimplePackageCodecDependencies(null, mockDeserializer);
- }
-
- @Test
- public void testDeserializationIsDelegatedToPackageDeserializer()
- throws SerializationException, IOException, PackageDeserializationException,
- InterruptedException {
- // Mock because all we need is to verify that we're properly delegating to Package deserializer.
- Package mockPackage = mock(Package.class);
-
- when(mockDeserializer.deserialize(
- any(DeserializationContext.class), any(CodedInputStream.class))).thenReturn(mockPackage);
-
- CodedInputStream codedIn = CodedInputStream.newInstance(new byte[] {1, 2, 3, 4});
- PackageValue result =
- underTest.deserialize(
- new DeserializationContext(ImmutableMap.of(PackageCodecDependencies.class, codecDeps)),
- codedIn);
-
- assertThat(result.getPackage()).isSameAs(mockPackage);
- }
-
- @Test
- public void testInterruptedExceptionRaisesIllegalStateException() throws Exception {
- InterruptedException staged = new InterruptedException("Stop that!");
- doThrow(staged).when(mockDeserializer)
- .deserialize(any(DeserializationContext.class), any(CodedInputStream.class));
-
- try {
- underTest.deserialize(
- new DeserializationContext(ImmutableMap.of(PackageCodecDependencies.class, codecDeps)),
- CodedInputStream.newInstance(new byte[] {1, 2, 3, 4}));
- fail("Expected exception");
- } catch (IllegalStateException e) {
- assertThat(e)
- .hasMessageThat()
- .isEqualTo("Unexpected InterruptedException during Package deserialization");
- assertThat(e).hasCauseThat().isSameAs(staged);
- }
- }
-}
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/serialization/ObjectCodecsTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/serialization/ObjectCodecsTest.java
index dc835c7920..f6448dfea4 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/serialization/ObjectCodecsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/serialization/ObjectCodecsTest.java
@@ -63,6 +63,9 @@ public class ObjectCodecsTest {
throws SerializationException, IOException {
return codedIn.readInt32();
}
+
+ /** Disables auto-registration. */
+ private static class IntegerCodecRegisterer implements CodecRegisterer<IntegerCodec> {}
}
private static final String KNOWN_CLASSIFIER = "KNOWN_CLASSIFIER";