Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ballerina/caller.bal
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ public isolated client class Caller {
}

# Retrieves the file content from a remote resource.
# Deprecated: Use the format specific get methods(`getJson`, `getXml`, `getCsv`, `getBytes`, `getText`) instead.
# ```ballerina
# stream<byte[] & readonly, io:Error?>|ftp:Error channel = caller->get(path);
# ```
#
# + path - The resource path
# + return - A byte stream from which the file can be read or `ftp:Error` in case of errors
# # Deprecated: Use the format specific get methods(`getJson`, `getXml`, `getCsv`, `getBytes`, `getText`) instead.
@deprecated
remote isolated function get(string path) returns stream<byte[] & readonly, io:Error?>|Error {
return self.'client->get(path);
Expand Down Expand Up @@ -142,22 +142,21 @@ public isolated client class Caller {
} external;

# Appends the content to an existing file in an FTP server.
# Deprecated: Use the format specific put methods(`putJson`, `putXml`, `putCsv`, `putBytes`, `putText`) instead.
# ```ballerina
# ftp:Error? response = caller->append(path, channel);
# ```
#
# + path - The resource path
# + content - Content to be written to the file in server
# + return - `()` or else an `ftp:Error` if failed to establish the communication with the FTP server
# # Deprecated: Use the format specific put methods(`putJson`, `putXml`, `putCsv`, `putBytes`, `putText`) instead.
@deprecated
remote isolated function append(string path, stream<byte[] & readonly, io:Error?>|string|xml|json content)
returns Error? {
return self.'client->append(path, content);
}

# Adds a file to an FTP server.
# Deprecated: Use the format specific put methods(`putJson`, `putXml`, `putCsv`, `putBytes`, `putText`) instead.
# ```ballerina
# ftp:Error? response = caller->put(path, channel);
# ```
Expand All @@ -166,6 +165,7 @@ public isolated client class Caller {
# + content - Content to be written to the file in server
# + compressionType - Type of the compression to be used if the file should be compressed before uploading
# + return - `()` or else an `ftp:Error` if failed to establish the communication with the FTP server
# # Deprecated: Use the format specific put methods(`putJson`, `putXml`, `putCsv`, `putBytes`, `putText`) instead.
@deprecated
remote isolated function put(string path, stream<byte[] & readonly, io:Error?>
|string|xml|json content, Compression compressionType = NONE) returns Error? {
Expand Down
6 changes: 3 additions & 3 deletions ballerina/client_endpoint.bal
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public isolated client class Client {
}

# Retrieves the file content from a remote resource.
# Deprecated: Use the format specific get methods(`getJson`, `getXml`, `getCsv`, `getBytes`, `getText`) instead.
# ```ballerina
# stream<byte[] & readonly, io:Error?>|ftp:Error channel = client->get(path);
# ```
#
# + path - The resource path
# + return - A byte stream from which the file can be read or `ftp:Error` in case of errors
# # Deprecated: Use the format specific get methods(`getJson`, `getXml`, `getCsv`, `getBytes`, `getText`) instead.
@deprecated
remote isolated function get(string path) returns stream<byte[] & readonly, io:Error?>|Error {
ByteStream|Error byteStream = new (self, path);
Expand Down Expand Up @@ -156,22 +156,21 @@ public isolated client class Client {
} external;

# Appends the content to an existing file in an FTP server.
# Deprecated: Use the format specific put methods(`putJson`, `putXml`, `putCsv`, `putBytes`, `putText`) instead.
# ```ballerina
# ftp:Error? response = client->append(path, channel);
# ```
#
# + path - The resource path
# + content - Content to be written to the file in server
# + return - `()` or else an `ftp:Error` if failed to establish the communication with the FTP server
# # Deprecated: Use the format specific put methods(`putJson`, `putXml`, `putCsv`, `putBytes`, `putText`) instead.
@deprecated
remote isolated function append(string path, stream<byte[] & readonly, io:Error?>|string|xml|json content)
returns Error? {
return append(self, getInputContent(path, content));
}

# Adds a file to an FTP server.
# Deprecated: Use the format specific put methods(`putJson`, `putXml`, `putCsv`, `putBytes`, `putText`) instead.
# ```ballerina
# ftp:Error? response = client->put(path, channel);
# ```
Expand All @@ -180,6 +179,7 @@ public isolated client class Client {
# + content - Content to be written to the file in server
# + compressionType - Type of the compression to be used if the file should be compressed before uploading
# + return - `()` or else an `ftp:Error` if failed to establish the communication with the FTP server
# # Deprecated: Use the format specific put methods(`putJson`, `putXml`, `putCsv`, `putBytes`, `putText`) instead.
@deprecated
remote isolated function put(string path, stream<byte[] & readonly, io:Error?>
|string|xml|json content, Compression compressionType = NONE) returns Error? {
Expand Down
66 changes: 34 additions & 32 deletions ballerina/tests/listener_on_file_deleted_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import ballerina/lang.runtime;
import ballerina/log;
import ballerina/test;

// Global tracking variables for onFileDeleted tests
// Global tracking variables for onFileDelete tests
string[] deletedFilesReceived = [];
int deleteEventCount = 0;
boolean deleteEventReceived = false;
Expand Down Expand Up @@ -106,15 +106,13 @@ public function testOnFileDeletedMultipleFiles() returns error? {
deleteEventCount = 0;
deleteEventReceived = false;

// Service with onFileDeleted
// Service with onFileDelete - called once per deleted file
Service deleteMultipleFilesService = service object {
remote function onFileDeleted(string[] deletedFiles) returns error? {
log:printInfo(string `onFileDeleted invoked with ${deletedFiles.length()} files`);
foreach string file in deletedFiles {
deletedFilesReceived.push(file);
deleteEventCount += 1;
deleteEventReceived = true;
}
remote function onFileDelete(string deletedFile) returns error? {
log:printInfo(string `onFileDelete invoked for: ${deletedFile}`);
deletedFilesReceived.push(deletedFile);
deleteEventCount += 1;
deleteEventReceived = true;
}
};

Expand Down Expand Up @@ -158,6 +156,7 @@ public function testOnFileDeletedMultipleFiles() returns error? {
test:assertTrue(deleteEventReceived, "Delete event should have been received");
test:assertTrue(deletedFilesReceived.length() >= 3,
string `Should have 3 deleted files, but got ${deletedFilesReceived.length()}`);
test:assertTrue(deleteEventCount >= 3, "Delete count should be at least 3");

// Verify all deleted files are in the list
boolean foundFileA = false;
Expand Down Expand Up @@ -188,11 +187,11 @@ public function testOnFileDeletedWithCaller() returns error? {
deletedFilesWithCaller = [];
deleteCallerEventReceived = false;

// Service with onFileDeleted and Caller
// Service with onFileDelete and Caller
Service deleteWithCallerService = service object {
remote function onFileDeleted(string[] deletedFiles, Caller caller) returns error? {
log:printInfo(string `onFileDeleted with Caller invoked with ${deletedFiles.length()} files`);
deletedFilesWithCaller = deletedFiles;
remote function onFileDelete(string deletedFile, Caller caller) returns error? {
log:printInfo(string `onFileDelete with Caller invoked for: ${deletedFile}`);
deletedFilesWithCaller.push(deletedFile);
deleteCallerEventReceived = true;

// Use caller to list remaining files
Expand Down Expand Up @@ -245,11 +244,11 @@ public function testOnFileDeletedWithFileNamePattern() returns error? {
deleteEventCount = 0;
deleteEventReceived = false;

// Service with onFileDeleted
// Service with onFileDelete
Service deletePatternService = service object {
remote function onFileDeleted(string[] deletedFiles) returns error? {
log:printInfo(string `onFileDeleted invoked with ${deletedFiles.length()} files`);
deletedFilesReceived = deletedFiles;
remote function onFileDelete(string deletedFile) returns error? {
log:printInfo(string `onFileDelete invoked for: ${deletedFile}`);
deletedFilesReceived.push(deletedFile);
deleteEventCount += 1;
deleteEventReceived = true;
}
Expand Down Expand Up @@ -292,14 +291,17 @@ public function testOnFileDeletedWithFileNamePattern() returns error? {
// Should only report the file matching the pattern (.deleted4)
test:assertTrue(deletedFilesReceived.length() >= 1,
"Should have only 1 deleted file (matching pattern)");
test:assertTrue(deletedFilesReceived[0].includes("matchingFile.deleted4"),
"Deleted file should be the one matching the pattern");

// Verify non-matching file was NOT reported
boolean foundMatchingFile = false;
foreach string deletedFile in deletedFilesReceived {
if deletedFile.includes("matchingFile.deleted4") {
foundMatchingFile = true;
}
// Verify non-matching file was NOT reported
test:assertFalse(deletedFile.includes("nonMatchingFile.other"),
"Non-matching file should not be in deleted files list");
}
test:assertTrue(foundMatchingFile, "Should find matchingFile.deleted4");
}

@test:Config {
Expand All @@ -312,11 +314,11 @@ public function testOnFileDeletedNoFilesDeleted() returns error? {
deleteEventCount = 0;
deleteEventReceived = false;

// Service with onFileDeleted
// Service with onFileDelete
Service deleteNoFilesService = service object {
remote function onFileDeleted(string[] deletedFiles) returns error? {
log:printInfo(string `onFileDeleted invoked with ${deletedFiles.length()} files`);
deletedFilesReceived = deletedFiles;
remote function onFileDelete(string deletedFile) returns error? {
log:printInfo(string `onFileDelete invoked for: ${deletedFile}`);
deletedFilesReceived.push(deletedFile);
deleteEventCount += 1;
deleteEventReceived = true;
}
Expand Down Expand Up @@ -344,7 +346,7 @@ public function testOnFileDeletedNoFilesDeleted() returns error? {
runtime:deregisterListener(deleteListener);
check deleteListener.gracefulStop();

// Assertions - onFileDeleted should NOT have been invoked
// Assertions - onFileDelete should NOT have been invoked
test:assertFalse(deleteEventReceived, "Delete event should NOT have been received when no files deleted");
test:assertEquals(deleteEventCount, 0, "Should have received 0 delete events");
}
Expand All @@ -357,10 +359,10 @@ public function testOnFileDeletedErrorHandling() returns error? {
// Reset state
deleteEventReceived = false;

// Service with onFileDeleted that throws an error
// Service with onFileDelete that throws an error
Service deleteErrorService = service object {
remote function onFileDeleted(string[] deletedFiles) returns error? {
log:printInfo(string `onFileDeleted invoked with ${deletedFiles.length()} files - throwing error`);
remote function onFileDelete(string deletedFile) returns error? {
log:printInfo(string `onFileDelete invoked for ${deletedFile} - throwing error`);
deleteEventReceived = true;
return error("Intentional error for testing");
}
Expand Down Expand Up @@ -406,11 +408,11 @@ public function testOnFileDeletedIsolatedService() returns error? {
deletedFilesReceived = [];
deleteEventReceived = false;

// Service with onFileDeleted (testing isolated compatibility)
// Service with onFileDelete (testing isolated compatibility)
Service isolatedDeleteService = service object {
remote function onFileDeleted(string[] deletedFiles) returns error? {
log:printInfo(string `onFileDeleted invoked with ${deletedFiles.length()} files`);
deletedFilesReceived = deletedFiles;
remote function onFileDelete(string deletedFile) returns error? {
log:printInfo(string `onFileDelete invoked for: ${deletedFile}`);
deletedFilesReceived.push(deletedFile);
deleteEventReceived = true;
}
};
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- [Added missing Commons VFS configuration parameters](https://github.com/ballerina-platform/ballerina-library/issues/8369)
- Add functionality for streaming put methods in ftp:Client
- Add functionality for type based put and get in ftp:Caller
- Deprecate `onFileDeleted` method and introduced `onFileDelete`

### Fixed

Expand Down
Loading
Loading