Skip to content

Commit

Permalink
Start implementing kryo registration #836
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-v authored and mergify-bot committed May 28, 2021
1 parent 27b6ae4 commit 0fa805d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
Expand All @@ -29,7 +30,9 @@
import de.retest.recheck.persistence.IncompatibleReportVersionException;
import de.retest.recheck.persistence.Persistable;
import de.retest.recheck.persistence.Persistence;
import de.retest.recheck.report.SuiteReplayResult;
import de.retest.recheck.report.TestReport;
import de.retest.recheck.ui.review.GoldenMasterSource;
import de.retest.recheck.util.FileUtil;
import de.retest.recheck.util.VersionProvider;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -78,6 +81,11 @@ private static Kryo createKryo() {

kryo.setRegistrationRequired( false ); // TODO remove, see #836

kryo.register( TestReport.class );
kryo.register( GoldenMasterSource.class );
kryo.register( SuiteReplayResult.class );
kryo.register( ArrayList.class );
// TODO add more, see #836

final Registration registration = kryo.register( TreeMultiset.class );
registration.setInstantiator( TreeMultiset::create );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand All @@ -24,6 +23,7 @@

import de.retest.recheck.persistence.IncompatibleReportVersionException;
import de.retest.recheck.persistence.Persistable;
import de.retest.recheck.report.SuiteReplayResult;
import de.retest.recheck.report.TestReport;
import de.retest.recheck.util.VersionProvider;

Expand All @@ -35,18 +35,18 @@ void roundtrip_should_work( @TempDir final Path temp ) throws IOException {
Files.createFile( file );
final URI identifier = file.toUri();

final KryoPersistence<de.retest.recheck.test.Test> kryoPersistence = new KryoPersistence<>();
final de.retest.recheck.test.Test persisted = createDummyTest();
final KryoPersistence<TestReport> kryoPersistence = new KryoPersistence<>();
final TestReport persisted = createDummyTest();
kryoPersistence.save( identifier, persisted );
final de.retest.recheck.test.Test loaded = kryoPersistence.load( identifier );
final TestReport loaded = kryoPersistence.load( identifier );

assertThat( persisted.getRelativeActionSequencePaths() ).isEqualTo( loaded.getRelativeActionSequencePaths() );
assertThat( loaded.getSuiteReplayResults().get( 0 ).getName() )
.isEqualTo( persisted.getSuiteReplayResults().get( 0 ).getName() );
}

public de.retest.recheck.test.Test createDummyTest() {
final ArrayList<String> tests = new ArrayList<>();
tests.add( "../test.test" );
return new de.retest.recheck.test.Test( tests );
public TestReport createDummyTest() {
final SuiteReplayResult suite = new SuiteReplayResult( "test", 23, null, "00", null );
return new TestReport( suite );
}

@Test
Expand All @@ -55,13 +55,12 @@ void incompatible_version_should_give_persisting_version( @TempDir final Path te
Files.createFile( file );
final URI identifier = file.toUri();

final KryoPersistence<de.retest.recheck.test.Test> kryoPersistence = new KryoPersistence<>();
final KryoPersistence<TestReport> kryoPersistence = new KryoPersistence<>();
kryoPersistence.save( identifier, createDummyTest() );

final Kryo kryoMock = mock( Kryo.class );
when( kryoMock.readClassAndObject( any() ) ).thenThrow( KryoException.class );
final KryoPersistence<de.retest.recheck.test.Test> differentKryoPersistence =
new KryoPersistence<>( kryoMock, "old Version" );
final KryoPersistence<TestReport> differentKryoPersistence = new KryoPersistence<>( kryoMock, "old Version" );

assertThatThrownBy( () -> differentKryoPersistence.load( identifier ) )
.isInstanceOf( IncompatibleReportVersionException.class )
Expand Down Expand Up @@ -99,8 +98,7 @@ void on_error_file_should_be_deleted() throws IOException {
final File nonexistent = new File( "nonexistent.report" );
final Kryo kryoMock = mock( Kryo.class );
doThrow( KryoException.class ).when( kryoMock ).writeClassAndObject( any(), any() );
final KryoPersistence<de.retest.recheck.test.Test> persistence =
new KryoPersistence<>( kryoMock, "some version" );
final KryoPersistence<TestReport> persistence = new KryoPersistence<>( kryoMock, "some version" );
assertThatThrownBy( () -> persistence.save( nonexistent.toURI(), createDummyTest() ) )
.isInstanceOf( KryoException.class );
assertThat( nonexistent ).doesNotExist();
Expand Down

0 comments on commit 0fa805d

Please sign in to comment.