Skip to content

Commit dff3619

Browse files
committed
[test](catalog) Add unit tests for Replica schemaHash polymorphism
Add four tests to ReplicaTest covering the schemaHash behavior change: - testLocalReplicaGetSchemaHash: constructor value is returned - testLocalReplicaSetSchemaHash: setter updates the value - testBaseReplicaSchemaHashReturnsNegativeOne: base class returns -1, setter is no-op - testCloudReplicaSchemaHashReturnsNegativeOne: CloudReplica inherits -1 stub Generated by ThinkOps
1 parent d006860 commit dff3619

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

fe/fe-core/src/test/java/org/apache/doris/catalog/ReplicaTest.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.doris.catalog;
1919

2020
import org.apache.doris.catalog.Replica.ReplicaState;
21+
import org.apache.doris.cloud.catalog.CloudReplica;
2122
import org.apache.doris.common.io.Text;
2223
import org.apache.doris.persist.gson.GsonUtils;
2324

@@ -194,4 +195,41 @@ public void testUpdateVersion3() {
194195
Assert.assertEquals(18, originalReplica.getVersion());
195196
Assert.assertEquals(-1, originalReplica.getLastFailedVersion());
196197
}
198+
199+
@Test
200+
public void testLocalReplicaGetSchemaHash() {
201+
int schemaHash = 12345;
202+
LocalReplica localReplica = new LocalReplica(10000, 20000, 3, schemaHash,
203+
100, 0, 78, ReplicaState.NORMAL, 0, 3);
204+
Assert.assertEquals(schemaHash, localReplica.getSchemaHash());
205+
}
206+
207+
@Test
208+
public void testLocalReplicaSetSchemaHash() {
209+
LocalReplica localReplica = new LocalReplica(10000, 20000, 3, 111,
210+
100, 0, 78, ReplicaState.NORMAL, 0, 3);
211+
Assert.assertEquals(111, localReplica.getSchemaHash());
212+
localReplica.setSchemaHash(222);
213+
Assert.assertEquals(222, localReplica.getSchemaHash());
214+
}
215+
216+
@Test
217+
public void testBaseReplicaSchemaHashReturnsNegativeOne() {
218+
// Base Replica (and by extension CloudReplica) should return -1 for schemaHash
219+
// since schemaHash is only meaningful for LocalReplica
220+
Replica baseReplica = new Replica();
221+
Assert.assertEquals(-1, baseReplica.getSchemaHash());
222+
223+
// setSchemaHash is a no-op on base Replica
224+
baseReplica.setSchemaHash(999);
225+
Assert.assertEquals(-1, baseReplica.getSchemaHash());
226+
}
227+
228+
@Test
229+
public void testCloudReplicaSchemaHashReturnsNegativeOne() {
230+
// CloudReplica extends Replica (not LocalReplica), so it inherits the -1 stub
231+
CloudReplica cloudReplica = new CloudReplica(10000L, 20000L, ReplicaState.NORMAL,
232+
3, 12345, 1, 2, 3, 4, -1);
233+
Assert.assertEquals(-1, cloudReplica.getSchemaHash());
234+
}
197235
}

0 commit comments

Comments
 (0)