Compare commits

...

6 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire bbe7b344ec Merge branch 'nextgen' into nextgen_queue_remove 2023-05-04 09:47:51 +02:00
Tristan B. Velloza Kildaire e0977837af Merge branch 'master' into nextgen 2023-05-04 09:47:39 +02:00
Tristan B. Velloza Kildaire 79432cef6c
Enable CI for `nextgen` branch
- Run CI tests for any pull requests being made to the `nextgen` branch
2023-05-04 09:46:46 +02:00
Tristan B. Velloza Kildaire b283ebcdfc Merge branch 'nextgen' into nextgen_queue_remove 2023-05-04 09:46:15 +02:00
Tristan B. Velloza Kildaire 89fce3bae9 Unit tests
- Added a TODO
2023-05-04 09:45:26 +02:00
Tristan B. Velloza Kildaire 798acba4aa Manager
- Implemented `releaseQueue(Queue)`
- Implemented `releaseQueue_nothrow(Queue)`

Unit tests

- Added unit test for `releaseQueue(Queue)`
2023-05-04 09:45:06 +02:00
2 changed files with 90 additions and 3 deletions

View File

@ -8,7 +8,7 @@ on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
branches: [ "master", "nextgen" ]
permissions:
contents: read

View File

@ -265,7 +265,61 @@ public class Manager
return true;
}
// TODO: Impkement releaseQueu_nothrow and releaseQueue
/**
* De-registers the given queue from the manager
*
* Params:
* queue = the queue to de-register
* Throws:
* TristanableException if a queue with the provided id cannot be found
*/
public void releaseQueue(Queue queue)
{
/* Try to de-register the queue */
bool status = releaseQueue_nothrow(queue);
/* If de-registration was not successful */
if(!status)
{
throw new TristanableException(ErrorType.QUEUE_NOT_FOUND);
}
}
/**
* De-registers the given queue from the manager
*
* Params:
* queue = the queue to de-register
* Returns: true if de-registration was successful, false otherwise
*/
public bool releaseQueue_nothrow(Queue queue)
{
/* Lock the queue of queues */
queuesLock.lock();
/* On return or error */
scope(exit)
{
/* Unlock the queue of queues */
queuesLock.unlock();
}
/* Search for the queue, return false if it does NOT exist */
foreach(Queue curQueue; queues)
{
if(curQueue.getID() == queue.getID())
{
/* Remove the queue */
queues.linearRemoveElement(queue);
/* De-registration succeeded */
return true;
}
}
/* De-registration failed */
return false;
}
/**
* Sets the default queue
@ -441,6 +495,37 @@ unittest
}
}
/**
* Tests registering a queue, de-registering it and
* then registering it again
*/
unittest
{
/* Create a manager */
Manager manager = new Manager(nullSock);
/* Create a new queue with tag 69 */
Queue queue = new Queue(69);
/* Register the queue */
manager.registerQueue(queue);
/* Ensure it is registered */
assert(queue == manager.getQueue(69));
/* De-register the queue */
manager.releaseQueue(queue);
/* Ensure it is de-registered */
assert(manager.getQueue_nothrow(69) is null);
/* Register the queue (again) */
manager.registerQueue(queue);
/* Ensure it is registered (again) */
assert(queue == manager.getQueue(69));
}
/**
* Tests registering a queue using the "next available queue"
* method
@ -459,4 +544,6 @@ unittest
assert(queue1.getID() == 0);
assert(queue2.getID() == 1);
assert(queue3.getID() == 2);
}
}
// TODO: Add testing for queue existence (internal method)