Skip to content

Commit 8711734

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 e391c65 commit 8711734

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

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

0 commit comments

Comments
 (0)