@Override
    public boolean equals(Object o) {
        if (o == this) return true;
        if (! (o instanceof RawConfig)) return false;

        RawConfig other = (RawConfig) o;
        if (! (key.equals(other.key) && defMd5.equals(other.defMd5) && (errorCode == other.errorCode)) )
            return false;

        // Need to check error codes before isError, since unequal error codes always means unequal requests,
        // while non-zero and equal error codes means configs are equal.
        if (isError()) return true;
        if (generation != other.generation) return false;
        return (payloadChecksums.equals(((RawConfig) o).payloadChecksums));
    }
@Test
    public void testEquals() {
        RawConfig config = new RawConfig(key, defMd5);

        assertThat(config, is(new RawConfig(key, defMd5)));
        assertThat(config, is(not(new RawConfig(key, "a")))); // different def md5
        assertThat(config.hashCode(), is(new RawConfig(key, defMd5).hashCode()));
        assertThat(config.hashCode(), is(not(new RawConfig(key, "a").hashCode()))); // different def md5

        // different generation
        config = new RawConfig(key, defMd5, payload, payloadChecksums, generation, false, defContent, Optional.empty());
        RawConfig config2 = new RawConfig(key, defMd5, payload, payloadChecksums, 2L, false, defContent, Optional.empty());
        assertThat(config, is(not(config2)));
        assertThat(config.hashCode(), is(not(config2.hashCode())));

        // different config md5 and with vespa version
        final VespaVersion vespaVersion = VespaVersion.fromString("5.37.38");
        RawConfig config3 = new RawConfig(key, defMd5, payload, PayloadChecksums.from("9999", ""), generation, false, defContent, Optional.of(vespaVersion));
        assertThat(config, is(not(config3)));
        assertThat(config.hashCode(), is(not(config3.hashCode())));
        // Check that vespa version is set correctly
        assertThat(config3.getVespaVersion().get().toString(), is(vespaVersion.toString()));
        assertThat(config.getVespaVersion(), is(not(config3.getVespaVersion())));

        // null config
        assertNotEquals(null, config);

        // different type of object
        assertNotEquals(config, key);

        // errors
        RawConfig errorConfig1 = new RawConfig(key, defMd5, payload, payloadChecksums, generation, false, 1, defContent, Optional.empty());
        assertThat(errorConfig1, is(errorConfig1));
        assertThat(config, is(not(errorConfig1)));
        assertThat(config.hashCode(), is(not(errorConfig1.hashCode())));
        assertThat(errorConfig1, is(errorConfig1));
        RawConfig errorConfig2 = new RawConfig(key, defMd5, payload, payloadChecksums, generation, false, 2, defContent, Optional.empty());
        assertThat(errorConfig1, is(not(errorConfig2)));
        assertThat(errorConfig1.hashCode(), is(not(errorConfig2.hashCode())));
    }