|
2 | 2 |
|
3 | 3 | import com.orientechnologies.BaseMemoryDatabase; |
4 | 4 | import com.orientechnologies.orient.core.config.OGlobalConfiguration; |
| 5 | +import com.orientechnologies.orient.core.db.document.ODatabaseDocumentEmbedded; |
5 | 6 | import com.orientechnologies.orient.core.db.record.OIdentifiable; |
6 | 7 | import com.orientechnologies.orient.core.db.record.ridbag.ORidBag; |
7 | 8 | import com.orientechnologies.orient.core.exception.OConcurrentModificationException; |
8 | 9 | import com.orientechnologies.orient.core.id.ORID; |
9 | 10 | import com.orientechnologies.orient.core.record.impl.ODocument; |
| 11 | +import com.orientechnologies.orient.core.storage.index.sbtreebonsai.local.OSBTreeBonsai; |
10 | 12 | import java.util.ArrayList; |
11 | 13 | import java.util.Arrays; |
12 | 14 | import java.util.HashMap; |
@@ -1138,6 +1140,62 @@ public void testFromSBTreeToEmbeddedRollback() { |
1138 | 1140 | Assert.assertTrue(docsToAdd.isEmpty()); |
1139 | 1141 | } |
1140 | 1142 |
|
| 1143 | + @Test |
| 1144 | + public void testFromSBTreeToEmbedded() { |
| 1145 | + OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(5); |
| 1146 | + OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD.setValue(7); |
| 1147 | + |
| 1148 | + List<OIdentifiable> docsToAdd = new ArrayList<OIdentifiable>(); |
| 1149 | + |
| 1150 | + ODocument document = new ODocument(); |
| 1151 | + |
| 1152 | + ORidBag ridBag = new ORidBag(); |
| 1153 | + document.field("ridBag", ridBag); |
| 1154 | + document.save(db.getClusterNameById(db.getDefaultClusterId())); |
| 1155 | + |
| 1156 | + db.begin(); |
| 1157 | + |
| 1158 | + for (int i = 0; i < 10; i++) { |
| 1159 | + ODocument docToAdd = new ODocument(); |
| 1160 | + docToAdd.save(db.getClusterNameById(db.getDefaultClusterId())); |
| 1161 | + ridBag.add(docToAdd); |
| 1162 | + docsToAdd.add(docToAdd); |
| 1163 | + } |
| 1164 | + |
| 1165 | + document.save(db.getClusterNameById(db.getDefaultClusterId())); |
| 1166 | + |
| 1167 | + db.commit(); |
| 1168 | + |
| 1169 | + Assert.assertEquals(docsToAdd.size(), 10); |
| 1170 | + Assert.assertTrue(!ridBag.isEmbedded()); |
| 1171 | + |
| 1172 | + document = db.load(document.getIdentity()); |
| 1173 | + ridBag = document.field("ridBag"); |
| 1174 | + |
| 1175 | + db.begin(); |
| 1176 | + OBonsaiCollectionPointer pointer = |
| 1177 | + ((OSBTreeRidBag) ridBag.getDelegate()).getCollectionPointer(); |
| 1178 | + for (int i = 0; i < 4; i++) { |
| 1179 | + OIdentifiable docToRemove = docsToAdd.get(i); |
| 1180 | + ridBag.remove(docToRemove); |
| 1181 | + } |
| 1182 | + |
| 1183 | + Assert.assertTrue(document.isDirty()); |
| 1184 | + |
| 1185 | + document.save(db.getClusterNameById(db.getDefaultClusterId())); |
| 1186 | + db.commit(); |
| 1187 | + |
| 1188 | + OSBTreeBonsai<OIdentifiable, Integer> btree = |
| 1189 | + ((ODatabaseDocumentEmbedded) db).getSbTreeCollectionManager().loadSBTree(pointer); |
| 1190 | + |
| 1191 | + Assert.assertTrue(btree.isEmpty()); |
| 1192 | + |
| 1193 | + document = db.load(document.getIdentity()); |
| 1194 | + ridBag = document.field("ridBag"); |
| 1195 | + |
| 1196 | + Assert.assertTrue(ridBag.isEmbedded()); |
| 1197 | + } |
| 1198 | + |
1141 | 1199 | @Test |
1142 | 1200 | public void testFromSBTreeToEmbeddedTxWithCME() { |
1143 | 1201 | OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(5); |
|
0 commit comments