From 00f47cc40e38c636fa26ae14a936028d5f8930c4 Mon Sep 17 00:00:00 2001
From: labkey-susanh
Date: Thu, 1 Oct 2026 09:29:48 -0700
Subject: [PATCH] GH Issue 1591: Stream and batch updates for text choice
values for better memory usage
---
.../test/tests/TextChoiceSampleTypeTest.java | 99 +++++++++++++++++++
1 file changed, 99 insertions(+)
diff --git a/src/org/labkey/test/tests/TextChoiceSampleTypeTest.java b/src/org/labkey/test/tests/TextChoiceSampleTypeTest.java
index fb24f349be..658fbe47be 100644
--- a/src/org/labkey/test/tests/TextChoiceSampleTypeTest.java
+++ b/src/org/labkey/test/tests/TextChoiceSampleTypeTest.java
@@ -15,12 +15,20 @@
*/
package org.labkey.test.tests;
+import org.json.JSONArray;
+import org.json.JSONObject;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.labkey.junit.LabKeyAssert;
import org.labkey.remoteapi.CommandException;
+import org.labkey.remoteapi.Connection;
+import org.labkey.remoteapi.domain.Domain;
+import org.labkey.remoteapi.domain.PropertyDescriptor;
+import org.labkey.remoteapi.domain.SaveDomainCommand;
+import org.labkey.remoteapi.query.ContainerFilter;
+import org.labkey.remoteapi.query.SelectRowsCommand;
import org.labkey.test.BaseWebDriverTest;
import org.labkey.test.Locator;
import org.labkey.test.categories.Daily;
@@ -33,6 +41,7 @@
import org.labkey.test.params.experiment.SampleTypeDefinition;
import org.labkey.test.util.AuditLogHelper;
import org.labkey.test.util.DataRegionTable;
+import org.labkey.test.util.EscapeUtil;
import org.labkey.test.util.PortalHelper;
import org.labkey.test.util.SampleTypeHelper;
import org.labkey.test.util.TestDataGenerator;
@@ -728,4 +737,94 @@ public void testSetTextChoiceValueForSample() throws IOException, CommandExcepti
String.format("Value '%s' for field '%s' is invalid.", invalidValue, textChoiceFieldCaption), errorMsg.getText());
}
+ /**
+ *
+ * Rename TextChoice values in use by more rows than the server updates in one batch.
+ *
+ *
+ * This test will:
+ *
+ * - Create samples in the project and a subfolder using values A, B and C.
+ * - Rename A -> B, B -> C and C -> D in a single domain save.
+ * - Verify each sample was mapped exactly once from its original value.
+ *
+ *
+ */
+ @Test
+ public void testChainedValueUpdatesAcrossBatches() throws IOException, CommandException
+ {
+ String sampleTypeName = "Test_TC_Chained_Updates";
+ String textChoiceFieldName = "StatusChoice";
+ String subfolder = "ChainedUpdatesSubfolder";
+ String subfolderPath = getProjectName() + "/" + subfolder;
+ Map valueUpdates = Map.of("A", "B", "B", "C", "C", "D");
+ // More than one server-side batch (1000 rows) for A and B
+ Map rowCounts = Map.of("A", 1100, "B", 1100, "C", 300);
+
+ _containerHelper.createSubfolder(getProjectName(), subfolder);
+
+ FieldDefinition textChoiceField = new FieldDefinition(textChoiceFieldName, ColumnType.TextChoice)
+ .setTextChoiceValues(List.of("A", "B", "C"));
+ TestDataGenerator dataGenerator = SampleTypeAPIHelper.createEmptySampleType(getProjectName(),
+ new SampleTypeDefinition(sampleTypeName).setFields(List.of(textChoiceField)));
+
+ log("Insert samples, alternating between the project and the subfolder so each batch spans both containers.");
+ List