Pass all test cases

This commit is contained in:
Max O'Cull 2019-02-24 20:01:19 -05:00
parent edcf0e8b80
commit fb47df2a7a
2 changed files with 69 additions and 59 deletions

View File

@ -2,7 +2,6 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="d7d3389b-0262-48b5-81ce-827f8aae7d1b" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/bufmgr/BufMgr.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/bufmgr/BufMgr.java" afterDir="false" />
</list>
<ignored path="$PROJECT_DIR$/out/" />
@ -32,7 +31,7 @@
</usages-collector>
<usages-collector id="statistics.file.types.edit">
<counts>
<entry key="JAVA" value="2946" />
<entry key="JAVA" value="3505" />
<entry key="PLAIN_TEXT" value="2" />
</counts>
</usages-collector>
@ -43,8 +42,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/tests/BMTest.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="404">
<caret line="778" selection-start-line="778" selection-end-line="778" />
<state relative-caret-position="184">
<caret line="575" selection-start-line="575" selection-end-line="575" />
</state>
</provider>
</entry>
@ -70,17 +69,17 @@
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/bufmgr/BufMgr.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="379">
<caret line="110" column="24" selection-start-line="110" selection-start-column="24" selection-end-line="110" selection-end-column="24" />
<state relative-caret-position="300">
<caret line="164" column="42" selection-start-line="164" selection-start-column="42" selection-end-line="164" selection-end-column="42" />
<folding>
<element signature="e#13728#13729#0" expanded="true" />
<element signature="e#13762#13763#0" expanded="true" />
<element signature="e#14251#14252#0" expanded="true" />
<element signature="e#14292#14293#0" expanded="true" />
<element signature="e#14342#14343#0" expanded="true" />
<element signature="e#14384#14385#0" expanded="true" />
<element signature="e#14435#14436#0" expanded="true" />
<element signature="e#14493#14494#0" expanded="true" />
<element signature="e#14808#14809#0" expanded="true" />
<element signature="e#14842#14843#0" expanded="true" />
<element signature="e#15331#15332#0" expanded="true" />
<element signature="e#15372#15373#0" expanded="true" />
<element signature="e#15422#15423#0" expanded="true" />
<element signature="e#15464#15465#0" expanded="true" />
<element signature="e#15515#15516#0" expanded="true" />
<element signature="e#15573#15574#0" expanded="true" />
</folding>
</state>
</provider>
@ -308,34 +307,34 @@
<servers />
</component>
<component name="TestHistory">
<history-entry file="BMTest_TestL_NewPageDeallocation - 2019.02.24 at 17h 23m 53s.xml">
<configuration name="BMTest.TestL_NewPageDeallocation" configurationId="JUnit" />
</history-entry>
<history-entry file="BMTest - 2019.02.24 at 17h 27m 01s.xml">
<history-entry file="BMTest - 2019.02.24 at 18h 45m 17s.xml">
<configuration name="BMTest" configurationId="JUnit" />
</history-entry>
<history-entry file="BMTest - 2019.02.24 at 17h 29m 37s.xml">
<history-entry file="BMTest - 2019.02.24 at 18h 45m 21s.xml">
<configuration name="BMTest" configurationId="JUnit" />
</history-entry>
<history-entry file="BMTest - 2019.02.24 at 17h 33m 36s.xml">
<history-entry file="BMTest - 2019.02.24 at 18h 45m 50s.xml">
<configuration name="BMTest" configurationId="JUnit" />
</history-entry>
<history-entry file="BMTest - 2019.02.24 at 17h 33m 47s.xml">
<history-entry file="BMTest - 2019.02.24 at 18h 48m 02s.xml">
<configuration name="BMTest" configurationId="JUnit" />
</history-entry>
<history-entry file="BMTest - 2019.02.24 at 17h 33m 58s.xml">
<history-entry file="BMTest - 2019.02.24 at 19h 39m 20s.xml">
<configuration name="BMTest" configurationId="JUnit" />
</history-entry>
<history-entry file="BMTest - 2019.02.24 at 17h 34m 23s.xml">
<history-entry file="BMTest - 2019.02.24 at 19h 45m 22s.xml">
<configuration name="BMTest" configurationId="JUnit" />
</history-entry>
<history-entry file="BMTest - 2019.02.24 at 17h 34m 43s.xml">
<history-entry file="BMTest - 2019.02.24 at 19h 49m 03s.xml">
<configuration name="BMTest" configurationId="JUnit" />
</history-entry>
<history-entry file="BMTest - 2019.02.24 at 17h 35m 05s.xml">
<history-entry file="BMTest - 2019.02.24 at 19h 49m 11s.xml">
<configuration name="BMTest" configurationId="JUnit" />
</history-entry>
<history-entry file="BMTest - 2019.02.24 at 18h 18m 24s.xml">
<history-entry file="BMTest - 2019.02.24 at 19h 54m 05s.xml">
<configuration name="BMTest" configurationId="JUnit" />
</history-entry>
<history-entry file="BMTest - 2019.02.24 at 19h 57m 29s.xml">
<configuration name="BMTest" configurationId="JUnit" />
</history-entry>
</component>
@ -381,9 +380,15 @@
<breakpoints>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/tests/BMTest.java</url>
<line>769</line>
<line>575</line>
<properties />
<option name="timeStamp" value="20" />
<option name="timeStamp" value="24" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/tests/BMTest.java</url>
<line>581</line>
<properties />
<option name="timeStamp" value="26" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
@ -461,24 +466,24 @@
</entry>
<entry file="file://$PROJECT_DIR$/src/tests/BMTest.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="404">
<caret line="778" selection-start-line="778" selection-end-line="778" />
<state relative-caret-position="184">
<caret line="575" selection-start-line="575" selection-end-line="575" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/bufmgr/BufMgr.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="379">
<caret line="110" column="24" selection-start-line="110" selection-start-column="24" selection-end-line="110" selection-end-column="24" />
<state relative-caret-position="300">
<caret line="164" column="42" selection-start-line="164" selection-start-column="42" selection-end-line="164" selection-end-column="42" />
<folding>
<element signature="e#13728#13729#0" expanded="true" />
<element signature="e#13762#13763#0" expanded="true" />
<element signature="e#14251#14252#0" expanded="true" />
<element signature="e#14292#14293#0" expanded="true" />
<element signature="e#14342#14343#0" expanded="true" />
<element signature="e#14384#14385#0" expanded="true" />
<element signature="e#14435#14436#0" expanded="true" />
<element signature="e#14493#14494#0" expanded="true" />
<element signature="e#14808#14809#0" expanded="true" />
<element signature="e#14842#14843#0" expanded="true" />
<element signature="e#15331#15332#0" expanded="true" />
<element signature="e#15372#15373#0" expanded="true" />
<element signature="e#15422#15423#0" expanded="true" />
<element signature="e#15464#15465#0" expanded="true" />
<element signature="e#15515#15516#0" expanded="true" />
<element signature="e#15573#15574#0" expanded="true" />
</folding>
</state>
</provider>

View File

@ -106,27 +106,17 @@ public class BufMgr {
Page foundPage = new Page();
if (isFull) {
int index = -1;
Integer head = fifo.poll();
for (Integer item : fifo) {
Integer pointer = hashTable.get(item);
if (pointer != null && bufDescr[pointer].PinCount <= 0) {
index = pointer;
break;
if (head != null) {
index = hashTable.get(head);
if (bufDescr[index].PinCount > 0) {
throw new BufferPoolExceededException("No head found in FIFO Queue");
}
} else {
throw new BufferPoolExceededException("No head found in FIFO Queue");
}
if (index <= -1) {
throw new BufferPoolExceededException("No item found with 0 pin count");
}
// Integer head = fifo.poll();
//
// if (head != null) {
// index = hashTable.get(head);
// } else {
// throw new BufferPoolExceededException("No head found in FIFO Queue");
// }
if (bufDescr[index].DirtyBit) {
try {
// TODO: May be wrong error.
@ -175,7 +165,7 @@ public class BufMgr {
page.setPage(foundPage);
}
fifo.remove(foundEntry);
fifo.remove(hashTable.get(pageno.pid));
}
/**
@ -283,10 +273,25 @@ public class BufMgr {
}
if (nextIndex > 0) {
int move = nextIndex;
int relocate = nextIndex;
nextIndex--;
fifo.remove(hashTable.get(globalPageId.pid));
int destroy = hashTable.get(globalPageId.pid);
hashTable.remove(globalPageId.pid);
if (destroy == relocate) {
bufFrames[relocate] = null;
bufDescr[relocate] = null;
} else {
bufFrames[destroy] = bufFrames[relocate];
bufDescr[destroy] = bufDescr[relocate];
bufFrames[relocate] = null;
bufDescr[relocate] = null;
hashTable.put(bufDescr[destroy].PageNumber, destroy);
}
}
// then delete from disk