-
Notifications
You must be signed in to change notification settings - Fork 871
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7568 from orientechnologies/issue_7546_v2_2
Issue #7546 was fixed.
- Loading branch information
Showing
3 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
...orientechnologies/orient/core/storage/impl/local/paginated/InvalidRemovedFileIdsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package com.orientechnologies.orient.core.storage.impl.local.paginated; | ||
|
||
import com.orientechnologies.common.serialization.types.OIntegerSerializer; | ||
import com.orientechnologies.common.serialization.types.OLongSerializer; | ||
import com.orientechnologies.common.serialization.types.OStringSerializer; | ||
import com.orientechnologies.orient.core.db.ODatabase; | ||
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; | ||
import com.orientechnologies.orient.core.metadata.schema.OSchema; | ||
import com.orientechnologies.orient.core.storage.OStorage; | ||
import com.orientechnologies.orient.core.storage.cache.OWriteCache; | ||
import com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.RandomAccessFile; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
@Test | ||
public class InvalidRemovedFileIdsTest { | ||
|
||
public void testRemovedFileIds() throws Exception { | ||
final String buildDirectory = System.getProperty("buildDirectory", "."); | ||
final String dbPath = buildDirectory + File.separator + InvalidRemovedFileIdsTest.class.getSimpleName(); | ||
|
||
deleteDirectory(new File(dbPath)); | ||
|
||
ODatabaseDocumentTx db = new ODatabaseDocumentTx("plocal:" + dbPath); | ||
db.create(); | ||
|
||
OStorage storage = db.getStorage(); | ||
db.close(); | ||
storage.close(true, false); | ||
|
||
final RandomAccessFile fileMap = new RandomAccessFile(new File(dbPath, "name_id_map.cm"), "rw"); | ||
fileMap.seek(fileMap.length()); | ||
|
||
writeNameIdEntry(fileMap, "c1.cpm", -100); | ||
writeNameIdEntry(fileMap, "c1.pcl", -100); | ||
|
||
writeNameIdEntry(fileMap, "c2.cpm", -200); | ||
writeNameIdEntry(fileMap, "c2.pcl", -200); | ||
writeNameIdEntry(fileMap, "c2.pcl", -400); | ||
|
||
writeNameIdEntry(fileMap, "c3.cpm", -500); | ||
writeNameIdEntry(fileMap, "c3.pcl", -500); | ||
writeNameIdEntry(fileMap, "c4.cpm", -500); | ||
writeNameIdEntry(fileMap, "c4.pcl", -600); | ||
writeNameIdEntry(fileMap, "c4.cpm", -600); | ||
|
||
db = new ODatabaseDocumentTx("plocal:" + dbPath); | ||
db.open("admin", "admin"); | ||
|
||
db.set(ODatabase.ATTRIBUTES.MINIMUMCLUSTERS, 1); | ||
|
||
final OSchema schema = db.getMetadata().getSchema(); | ||
schema.createClass("c1"); | ||
schema.createClass("c2"); | ||
schema.createClass("c3"); | ||
schema.createClass("c4"); | ||
|
||
storage = db.getStorage(); | ||
OWriteCache writeCache = ((OAbstractPaginatedStorage) storage).getWriteCache(); | ||
|
||
final Map<String, Long> files = writeCache.files(); | ||
final Set<Long> ids = new HashSet<Long>(); | ||
|
||
final Long c1_cpm_id = files.get("c1.cpm"); | ||
Assert.assertNotNull(c1_cpm_id); | ||
Assert.assertTrue(c1_cpm_id > 0); | ||
Assert.assertTrue(ids.add(c1_cpm_id)); | ||
|
||
final Long c1_pcl_id = files.get("c1.pcl"); | ||
Assert.assertNotNull(c1_pcl_id); | ||
Assert.assertTrue(c1_pcl_id > 0); | ||
Assert.assertTrue(ids.add(c1_pcl_id)); | ||
|
||
final Long c2_cpm_id = files.get("c2.cpm"); | ||
Assert.assertNotNull(c2_cpm_id); | ||
Assert.assertTrue(ids.add(c2_cpm_id)); | ||
Assert.assertEquals(writeCache.internalFileId(c2_cpm_id), 200); //check that updated file map has been read | ||
|
||
final Long c2_pcl_id = files.get("c2.pcl"); | ||
Assert.assertNotNull(c2_pcl_id); | ||
Assert.assertTrue(ids.add(c2_pcl_id)); | ||
Assert.assertEquals(writeCache.internalFileId(c2_pcl_id), 400); //check that updated file map has been read | ||
|
||
final Long c3_cpm_id = files.get("c3.cpm"); | ||
Assert.assertNotNull(c3_cpm_id); | ||
Assert.assertTrue(c3_cpm_id > 0); | ||
Assert.assertTrue(ids.add(c3_cpm_id)); | ||
|
||
final Long c3_pcl_id = files.get("c3.pcl"); | ||
Assert.assertNotNull(c3_pcl_id); | ||
Assert.assertTrue(c3_pcl_id > 0); | ||
Assert.assertTrue(ids.add(c3_pcl_id)); | ||
|
||
final Long c4_cpm_id = files.get("c4.cpm"); | ||
Assert.assertNotNull(c4_cpm_id); | ||
Assert.assertTrue(c4_cpm_id > 0); | ||
Assert.assertTrue(ids.add(c4_cpm_id)); | ||
|
||
final Long c4_pcl_id = files.get("c4.pcl"); | ||
Assert.assertNotNull(c4_pcl_id); | ||
Assert.assertTrue(c1_pcl_id > 0); | ||
Assert.assertTrue(ids.add(c4_pcl_id)); | ||
|
||
db.close(); | ||
} | ||
|
||
private static void writeNameIdEntry(RandomAccessFile file, String name, int fileId) throws IOException { | ||
final int nameSize = OStringSerializer.INSTANCE.getObjectSize(name); | ||
|
||
byte[] serializedRecord = new byte[OIntegerSerializer.INT_SIZE + nameSize + OLongSerializer.LONG_SIZE]; | ||
OIntegerSerializer.INSTANCE.serializeLiteral(nameSize, serializedRecord, 0); | ||
OStringSerializer.INSTANCE.serialize(name, serializedRecord, OIntegerSerializer.INT_SIZE); | ||
OLongSerializer.INSTANCE.serializeLiteral(fileId, serializedRecord, OIntegerSerializer.INT_SIZE + nameSize); | ||
|
||
file.write(serializedRecord); | ||
} | ||
|
||
private static void deleteDirectory(final File directory) { | ||
if (directory.exists()) { | ||
final File[] files = directory.listFiles(); | ||
|
||
if (files != null) { | ||
for (File file : files) { | ||
if (file.isDirectory()) { | ||
deleteDirectory(file); | ||
} else { | ||
Assert.assertTrue(file.delete()); | ||
} | ||
} | ||
|
||
Assert.assertTrue(directory.delete()); | ||
} | ||
|
||
} | ||
} | ||
} |