Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 0xe299233a8efdcefd seed for ShortAccordSimulationTest #3839

Open
wants to merge 1 commit into
base: cep-15-accord
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public class LatestDepsSerializers
public void serialize(LatestDeps t, DataOutputPlus out, int version) throws IOException
{
out.writeUnsignedVInt32(t.size());
if (t.size() == 0)
return;

for (int i = 0 ; i < t.size() ; ++i)
{
RoutingKey start = t.startAt(i);
Expand All @@ -68,6 +71,9 @@ public void serialize(LatestDeps t, DataOutputPlus out, int version) throws IOEx
public LatestDeps deserialize(DataInputPlus in, int version) throws IOException
{
int size = in.readUnsignedVInt32();
if (size == 0)
return LatestDeps.EMPTY;

RoutingKey[] starts = new RoutingKey[size + 1];
LatestDeps.LatestEntry[] values = new LatestDeps.LatestEntry[size];
for (int i = 0 ; i < size ; ++i)
Expand All @@ -92,6 +98,8 @@ public long serializedSize(LatestDeps t, int version)
{
long size = 0;
size += TypeSizes.sizeofUnsignedVInt(t.size());
if (t.size() == 0)
return size;
for (int i = 0 ; i < t.size() ; ++i)
{
RoutingKey start = t.startAt(i);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.cassandra.service.accord.serializers;

import java.nio.ByteBuffer;
import java.util.List;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import accord.primitives.LatestDeps;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.dht.Murmur3Partitioner;
import org.apache.cassandra.io.util.DataInputBuffer;
import org.apache.cassandra.io.util.DataOutputBuffer;

import org.apache.cassandra.net.MessagingService.Version;

import static org.apache.cassandra.net.MessagingService.Version.VERSION_51;

public class LatestDepsSerializerTest
{
@BeforeClass
public static void setup()
{
DatabaseDescriptor.clientInitialization();
DatabaseDescriptor.setPartitionerUnsafe(Murmur3Partitioner.instance);
}

private static final List<Version> SUPPORTED_VERSIONS = VERSION_51.greaterThanOrEqual();

@Test
public void emptySerializerTest() throws Throwable
{
for (Version ver : SUPPORTED_VERSIONS)
{
ByteBuffer bb = null;
try (DataOutputBuffer buf = new DataOutputBuffer())
{
long expected = LatestDepsSerializers.latestDeps.serializedSize(LatestDeps.EMPTY, ver.value);
LatestDepsSerializers.latestDeps.serialize(LatestDeps.EMPTY, buf, ver.value);
bb = buf.asNewBuffer();
Assert.assertEquals(expected, bb.capacity());
}

try (DataInputBuffer in = new DataInputBuffer(bb, false))
{
LatestDeps roundTrip = LatestDepsSerializers.latestDeps.deserialize(in, ver.value);
Assert.assertEquals(roundTrip, LatestDeps.EMPTY);
}
}
}
}