Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 2, 2025

This PR adds comprehensive tests for file locking functionality for SEQUENTIAL, LINE-SEQUENTIAL, and RELATIVE file organizations to tests/run.src/miscellaneous.at.

Changes Made

Test Coverage Added

Added 3 new test cases that verify file locking behavior:

  1. File locking - SEQUENTIAL files (Test Run NIST85 tests for Relative files and add the test status to README.md #108)
  2. File locking - LINE SEQUENTIAL files (Test Refactor source code based on the result of static analysis #109)
  3. File locking - RELATIVE files (Test The output data of DISPLAY statement against data specified PIC PP99 is wrong #110)

Each test verifies all open modes work correctly:

  • OUTPUT mode (file creation with shared lock)
  • INPUT mode (read access with exclusive lock)
  • I-O mode (read/write access with exclusive lock)
  • EXTEND mode (append access with exclusive lock)

Implementation Analysis

Through code analysis, confirmed that file locking is already implemented for all three file types in the base CobolFile class:

  • Location: libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java
  • Method: open_(String filename, int mode, int sharing)
  • Technology: Uses Java NIO FileLock with tryLock()
  • Error Handling: Returns file status 61 (COB_STATUS_61_FILE_SHARING) when file locking fails

Lock Behavior

// OUTPUT mode uses shared locks, other modes use exclusive locks
boolean lockFlag;
if (sharing != 0 || mode == COB_OPEN_OUTPUT) {
    lockFlag = false;  // Shared lock
} else {
    lockFlag = true;   // Exclusive lock
}

Documentation

Added doc/file-locking-implementation.md documenting:

  • Implementation details and lock type determination
  • Error handling and file status codes
  • Test coverage and scenarios

The tests demonstrate that file locking functionality exists and works correctly for SEQUENTIAL, LINE-SEQUENTIAL, and RELATIVE files as requested.

Fixes #709.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 3 commits September 2, 2025 08:36
Co-authored-by: yutaro-sakamoto <80912876+yutaro-sakamoto@users.noreply.github.com>
…files

Co-authored-by: yutaro-sakamoto <80912876+yutaro-sakamoto@users.noreply.github.com>
Co-authored-by: yutaro-sakamoto <80912876+yutaro-sakamoto@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Test file locking of SEQUENTIAL, LINE-SEQUENTIAL, RELATIVE Add file locking tests for SEQUENTIAL, LINE-SEQUENTIAL, and RELATIVE files Sep 2, 2025
@Copilot Copilot AI requested a review from yutaro-sakamoto September 2, 2025 08:48
Copilot finished work on behalf of yutaro-sakamoto September 2, 2025 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test file locking of SEQUENTIAL, LINE-SEQUENTIAL, RELATIVE
2 participants