22
22
import org .slf4j .LoggerFactory ;
23
23
24
24
public class RsyncTestRunner {
25
+
25
26
@ SuppressWarnings ("unused" )
26
27
private static final Logger LOG = LoggerFactory .getLogger (RsyncTestRunner .class );
27
28
@@ -64,34 +65,40 @@ public boolean isFlag(Flag flag) {
64
65
return flags .contains (flag );
65
66
}
66
67
67
- private List <Checksum > checksum () throws Exception {
68
- if (isFlag (Flag .PrintServerRaw ))
68
+ private List <Checksum > checksum () throws Exception {
69
+ if (isFlag (Flag .PrintServerRaw )) {
69
70
LOG .debug ("Server (initial) data is " + Arrays .toString (serverData .read ()));
71
+ }
70
72
ChecksumGenerator generator = new ChecksumGenerator (blockSize );
71
73
List <Checksum > checksums = new ArrayList <>();
72
74
generator .generate (checksums ::add , serverData );
73
- if (isFlag (Flag .PrintChecksums ))
75
+ if (isFlag (Flag .PrintChecksums )) {
74
76
LOG .debug ("Server checksums are " + checksums );
77
+ }
75
78
return checksums ;
76
79
}
77
80
78
- private List <Instruction > instruct (List <Checksum > checksums ) throws Exception {
79
- if (isFlag (Flag .PrintClientRaw ))
81
+ private List <Instruction > instruct (List <Checksum > checksums ) throws Exception {
82
+ if (isFlag (Flag .PrintClientRaw )) {
80
83
LOG .debug ("Client data is " + Arrays .toString (clientData .read ()));
84
+ }
81
85
List <Instruction > instructions = new ArrayList <>();
82
86
InstructionGenerator matcher = new InstructionGenerator (blockSize );
83
87
matcher .generate (instructions ::add , clientData , checksums );
84
- if (isFlag (Flag .PrintInstructions ))
88
+ if (isFlag (Flag .PrintInstructions )) {
85
89
LOG .debug ("Client instructions are\n " + Joiner .on ('\n' ).join (instructions ));
90
+ }
86
91
int instructionSize = 0 ;
87
- for (Instruction instruction : instructions )
92
+ for (Instruction instruction : instructions ) {
88
93
instructionSize += instruction .getSerializedSize ();
94
+ }
89
95
LOG .debug ("Client instructions size is " + instructionSize );
90
96
return instructions ;
91
97
}
92
98
93
99
private void reconstruct (OutputStream out , List <Instruction > instructions ) throws Exception {
94
- try (InstructionReceiver receiver = new InstructionReceiver (out , serverData )) {
100
+ try (InstructionReceiver receiver = new InstructionReceiver (out ,
101
+ DummyDbsyncBytesCopier .wrap (serverData .read ()))) {
95
102
for (Instruction instruction : instructions ) {
96
103
// LOG.info("Instruction: " + instruction.toPrettyString());
97
104
receiver .receive (instruction );
@@ -103,8 +110,9 @@ private byte[] reconstruct(List<Instruction> instructions) throws Exception {
103
110
ByteArrayOutputStream out = new ByteArrayOutputStream ();
104
111
reconstruct (out , instructions );
105
112
byte [] serverDataNew = out .toByteArray ();
106
- if (isFlag (Flag .PrintServerNewRaw ))
113
+ if (isFlag (Flag .PrintServerNewRaw )) {
107
114
LOG .debug ("Server (result) data is " + Arrays .toString (serverDataNew ));
115
+ }
108
116
LOG .debug ("Server (result) data size is " + serverDataNew .length );
109
117
assertArrayEquals (clientData .read (), serverDataNew , name + " got mismatched data." );
110
118
return serverDataNew ;
0 commit comments