Skip to content

Commit

Permalink
getter functions for MemorySlot properties
Browse files Browse the repository at this point in the history
  • Loading branch information
lane-neuro committed Jul 28, 2024
1 parent e769f53 commit 597a1dd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
8 changes: 4 additions & 4 deletions research_analytics_suite/data_engine/memory/MemoryManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ async def create_slot(self, name: str, data: any, db_path: str = None, file_path
_id = uuid.uuid4().hex[:8]
memory_slot = MemorySlot(memory_id=_id, name=name, data=data, db_path=db_path, file_path=file_path)
await memory_slot.setup()
self._data_cache.set(key=memory_slot._memory_id, data=memory_slot)
return memory_slot._memory_id
self._data_cache.set(key=memory_slot.memory_id, data=memory_slot)
return memory_slot.memory_id

async def update_slot(self, memory_id: str, data: any) -> str:
"""
Expand Down Expand Up @@ -159,8 +159,8 @@ async def delete_slot(self, memory_id: str) -> None:
memory_slot = self._data_cache.get_key(key=memory_id)
if memory_slot:
memory_slot.close()
if memory_slot._file_path:
os.remove(memory_slot._file_path) # Remove memory-mapped file if it exists
if memory_slot.file_path:
os.remove(memory_slot.file_path) # Remove memory-mapped file if it exists
self._data_cache.delete(key=memory_id)

async def list_slots(self) -> dict:
Expand Down
18 changes: 18 additions & 0 deletions research_analytics_suite/data_engine/memory/MemorySlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,24 @@ def name(self, value: str) -> None:
"""
self._name = value

@property
def memory_id(self) -> str:
"""Gets the unique identifier for the memory slot.
Returns:
str: The unique identifier for the memory slot.
"""
return self._memory_id or ""

@property
def file_path(self) -> str:
"""Gets the file path for memory-mapped storage.
Returns:
str: The file path for memory-mapped storage.
"""
return self._file_path or ""

@property
async def data(self) -> any:
"""Gets the data stored in the memory slot."""
Expand Down
2 changes: 1 addition & 1 deletion tests/data_engine/memory/test_memory_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async def test_update_slot(self):
async def test_delete_slot(self):
memory_id = "12345678"
mock_slot = MagicMock(spec=MemorySlot)
mock_slot._file_path = "test_mmap.dat"
mock_slot.file_path = "test_mmap.dat"
self.memory_manager._data_cache.get_key.return_value = mock_slot

with patch('os.remove', MagicMock()) as mock_remove:
Expand Down

0 comments on commit 597a1dd

Please sign in to comment.