mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Add assertions to ensure the index has a write-lock when it is written to.
This commit is contained in:
parent
d1db017310
commit
2c80cfda68
6 changed files with 18 additions and 1 deletions
|
@ -53,6 +53,7 @@ public class BTreeTests extends BaseTestCase {
|
|||
protected void init(int degree) throws Exception {
|
||||
dbFile = File.createTempFile("pdomtest", "db");
|
||||
db = new Database(dbFile, new ChunkCache(), 0);
|
||||
db.setWritable();
|
||||
rootRecord = Database.DATA_AREA;
|
||||
comparator = new BTMockRecordComparator();
|
||||
btree = new BTree(db, rootRecord, degree, comparator);
|
||||
|
|
|
@ -38,6 +38,7 @@ public class DBPropertiesTests extends BaseTestCase {
|
|||
dbLoc = File.createTempFile("test", "db");
|
||||
dbLoc.deleteOnExit();
|
||||
db = new Database(dbLoc, new ChunkCache(), 0);
|
||||
db.setWritable();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
|
@ -45,6 +46,7 @@ public class DBPropertiesTests extends BaseTestCase {
|
|||
}
|
||||
|
||||
public void testBasic() throws CoreException {
|
||||
db.setWritable();
|
||||
DBProperties properties = new DBProperties(db);
|
||||
Properties expected = System.getProperties();
|
||||
for(Iterator i = expected.keySet().iterator(); i.hasNext(); ) {
|
||||
|
|
|
@ -127,6 +127,7 @@ public class DBTest extends BaseTestCase {
|
|||
File f = getTestDir().append("testStrings.dat").toFile();
|
||||
f.delete();
|
||||
final Database db = new Database(f, new ChunkCache(), 0);
|
||||
db.setWritable();
|
||||
|
||||
String[] names = {
|
||||
"ARLENE",
|
||||
|
|
|
@ -249,6 +249,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
|
|||
}
|
||||
|
||||
void reloadFromFile(File file) throws CoreException {
|
||||
assert lockCount < 0; // must have write lock.
|
||||
File oldFile= fPath;
|
||||
fLinkageIDCache.clear();
|
||||
try {
|
||||
|
@ -257,6 +258,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
|
|||
CCorePlugin.log(e);
|
||||
}
|
||||
loadDatabase(file, db.getChunkCache());
|
||||
db.setWritable();
|
||||
oldFile.delete();
|
||||
}
|
||||
|
||||
|
@ -750,7 +752,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
|
|||
db.resetCacheCounters();
|
||||
}
|
||||
|
||||
public void flush() throws CoreException {
|
||||
protected void flush() throws CoreException {
|
||||
db.flush();
|
||||
}
|
||||
|
||||
|
|
|
@ -72,6 +72,10 @@ public class WritablePDOM extends PDOM implements IWritableIndexFragment {
|
|||
super.clear();
|
||||
}
|
||||
|
||||
public void flush() throws CoreException {
|
||||
super.flush();
|
||||
}
|
||||
|
||||
public PDOMBinding addBinding(IASTName name) throws CoreException {
|
||||
PDOMBinding result= null;
|
||||
PDOMLinkage linkage= createLinkage(name.getLinkage().getID());
|
||||
|
|
|
@ -57,6 +57,7 @@ final class Chunk {
|
|||
}
|
||||
|
||||
public void putByte(int offset, byte value) {
|
||||
assert fLocked;
|
||||
fDirty= true;
|
||||
fBuffer.put(offset % Database.CHUNK_SIZE, value);
|
||||
}
|
||||
|
@ -73,12 +74,14 @@ final class Chunk {
|
|||
}
|
||||
|
||||
public void putBytes(int offset, byte[] bytes) {
|
||||
assert fLocked;
|
||||
fDirty= true;
|
||||
fBuffer.position(offset % Database.CHUNK_SIZE);
|
||||
fBuffer.put(bytes, 0, bytes.length);
|
||||
}
|
||||
|
||||
public void putInt(int offset, int value) {
|
||||
assert fLocked;
|
||||
fDirty= true;
|
||||
fBuffer.putInt(offset % Database.CHUNK_SIZE, value);
|
||||
}
|
||||
|
@ -88,6 +91,7 @@ final class Chunk {
|
|||
}
|
||||
|
||||
public void putShort(int offset, short value) {
|
||||
assert fLocked;
|
||||
fDirty= true;
|
||||
fBuffer.putShort(offset % Database.CHUNK_SIZE, value);
|
||||
}
|
||||
|
@ -101,11 +105,13 @@ final class Chunk {
|
|||
}
|
||||
|
||||
public void putLong(int offset, long value) {
|
||||
assert fLocked;
|
||||
fDirty= true;
|
||||
fBuffer.putLong(offset % Database.CHUNK_SIZE, value);
|
||||
}
|
||||
|
||||
public void putChar(int offset, char value) {
|
||||
assert fLocked;
|
||||
fDirty= true;
|
||||
fBuffer.putChar(offset % Database.CHUNK_SIZE, value);
|
||||
}
|
||||
|
@ -120,6 +126,7 @@ final class Chunk {
|
|||
}
|
||||
|
||||
void clear(int offset, int length) {
|
||||
assert fLocked;
|
||||
fDirty= true;
|
||||
fBuffer.position(offset % Database.CHUNK_SIZE);
|
||||
fBuffer.put(new byte[length]);
|
||||
|
|
Loading…
Add table
Reference in a new issue