Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
104 changes: 101 additions & 3 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@
dependencies-toml-version = "2"
distribution-version = "2201.12.0"

[[package]]
org = "ballerina"
name = "crypto"
version = "2.10.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "time"}
]
modules = [
{org = "ballerina", packageName = "crypto", moduleName = "crypto"}
]

[[package]]
org = "ballerina"
name = "data.csv"
Expand Down Expand Up @@ -47,13 +60,18 @@ org = "ballerina"
name = "ftp"
version = "2.16.0"
dependencies = [
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "data.csv"},
{org = "ballerina", name = "data.jsondata"},
{org = "ballerina", name = "data.xmldata"},
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.runtime"},
{org = "ballerina", name = "lang.string"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "task"}
{org = "ballerina", name = "task"},
{org = "ballerina", name = "test"},
{org = "ballerina", name = "time"}
]
modules = [
{org = "ballerina", packageName = "ftp", moduleName = "ftp"}
Expand All @@ -79,11 +97,74 @@ modules = [
{org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.__internal"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.object"}
]

[[package]]
org = "ballerina"
name = "lang.array"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.__internal"}
]

[[package]]
org = "ballerina"
name = "lang.error"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.object"
version = "0.0.0"

[[package]]
org = "ballerina"
name = "lang.regexp"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.runtime"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
modules = [
{org = "ballerina", packageName = "lang.runtime", moduleName = "lang.runtime"}
]

[[package]]
org = "ballerina"
name = "lang.string"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.regexp"}
]
modules = [
{org = "ballerina", packageName = "lang.string", moduleName = "lang.string"}
]

[[package]]
org = "ballerina"
name = "lang.value"
Expand Down Expand Up @@ -117,7 +198,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "task"
version = "2.7.0"
version = "2.11.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "time"}
Expand All @@ -126,11 +207,28 @@ modules = [
{org = "ballerina", packageName = "task", moduleName = "task"}
]

[[package]]
org = "ballerina"
name = "test"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.array"},
{org = "ballerina", name = "lang.error"}
]
modules = [
{org = "ballerina", packageName = "test", moduleName = "test"}
]

[[package]]
org = "ballerina"
name = "time"
version = "2.7.0"
version = "2.8.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
modules = [
{org = "ballerina", packageName = "time", moduleName = "time"}
]

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
Loading