Skip to content

Commit b9c4ecd

Browse files
Update c driver tests to 3.x and enable deployment (#795)
## Usage and product changes Update c driver tests to 3.x and enable deployment
1 parent a56654c commit b9c4ecd

File tree

11 files changed

+358
-494
lines changed

11 files changed

+358
-494
lines changed

.circleci/config.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ jobs:
529529

530530
- deploy-maven-jni-snapshot-unix
531531

532-
# - deploy-clib-snapshot-unix
532+
- deploy-clib-snapshot-unix
533533
# - test-clib-assembly-linux:
534534
# target-arch: arm64
535535

@@ -551,7 +551,7 @@ jobs:
551551

552552
- deploy-maven-jni-snapshot-unix
553553

554-
# - deploy-clib-snapshot-unix
554+
- deploy-clib-snapshot-unix
555555
# - test-clib-assembly-linux:
556556
# target-arch: x86_64
557557

@@ -575,7 +575,7 @@ jobs:
575575

576576
# - run: brew install cmake
577577

578-
# - deploy-clib-snapshot-unix
578+
- deploy-clib-snapshot-unix
579579
# - test-clib-assembly-mac:
580580
# target-arch: arm64
581581

@@ -599,7 +599,7 @@ jobs:
599599

600600
# - run: brew install cmake
601601

602-
# - deploy-clib-snapshot-unix
602+
- deploy-clib-snapshot-unix
603603
# - test-clib-assembly-mac:
604604
# target-arch: x86_64
605605

@@ -620,8 +620,8 @@ jobs:
620620

621621
- run: .circleci\windows\java\deploy_snapshot.bat
622622

623-
# - run: .circleci\windows\clib\deploy_snapshot.bat
624-
# - run: .circleci\windows\clib\test_assembly.bat
623+
- run: .circleci\windows\clib\deploy_snapshot.bat
624+
- run: .circleci\windows\clib\test_assembly.bat
625625

626626
# - run: .circleci\windows\cpp\deploy_snapshot.bat
627627
# - run: .circleci\windows\cpp\test_assembly.bat
@@ -728,7 +728,7 @@ jobs:
728728
bazel-arch: arm64
729729
- deploy-pip-release-unix
730730
- deploy-maven-jni-release-unix
731-
# - deploy-clib-release-unix
731+
- deploy-clib-release-unix
732732
# - deploy-cpp-release-unix
733733

734734
# - install-libicu-linux
@@ -742,7 +742,7 @@ jobs:
742742
bazel-arch: amd64
743743
- deploy-pip-release-unix
744744
- deploy-maven-jni-release-unix
745-
# - deploy-clib-release-unix
745+
- deploy-clib-release-unix
746746
# - deploy-cpp-release-unix
747747

748748
# - install-libicu-linux
@@ -756,7 +756,7 @@ jobs:
756756
bazel-arch: arm64
757757
- deploy-pip-release-unix
758758
- deploy-maven-jni-release-unix
759-
# - deploy-clib-release-unix
759+
- deploy-clib-release-unix
760760
# - deploy-cpp-release-unix
761761
# - deploy-dotnet-runtime-release-unix
762762

@@ -769,7 +769,7 @@ jobs:
769769
bazel-arch: amd64
770770
- deploy-pip-release-unix
771771
- deploy-maven-jni-release-unix
772-
# - deploy-clib-release-unix
772+
- deploy-clib-release-unix
773773
# - deploy-cpp-release-unix
774774
# - deploy-dotnet-runtime-release-unix
775775

@@ -781,7 +781,7 @@ jobs:
781781
- run: .circleci\windows\prepare.bat
782782
- run: .circleci\windows\python\deploy_release.bat
783783
- run: .circleci\windows\java\deploy_release.bat
784-
# - run: .circleci\windows\clib\deploy_release.bat
784+
- run: .circleci\windows\clib\deploy_release.bat
785785
# - run: .circleci\windows\cpp\deploy_release.bat
786786
# - run: .circleci\windows\csharp\deploy_release.bat
787787

.factory/automation.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,20 @@ build:
145145
# tool/test/stop-cluster-servers.sh
146146
# exit $TEST_SUCCESS
147147

148-
# test-c-integration:
149-
# image: typedb-ubuntu-20.04 # Ubuntu 20.04 has GLIBC version 2.31 (2020) which we should verify to compile against
150-
# dependencies:
151-
# - build
152-
# command: |
153-
# export ARTIFACT_USERNAME=$REPO_TYPEDB_USERNAME
154-
# export ARTIFACT_PASSWORD=$REPO_TYPEDB_PASSWORD
155-
# bazel run @typedb_dependencies//tool/bazelinstall:remote_cache_setup.sh
156-
# bazel run @typedb_dependencies//distribution/artifact:create-netrc
157-
# tool/test/start-community-server.sh &&
158-
# bazel test //c/tests/integration:test-driver --test_output=errors &&
159-
# export TEST_SUCCESS=0 || export TEST_SUCCESS=1
160-
# tool/test/stop-community-server.sh
161-
# exit $TEST_SUCCESS
148+
test-c-integration:
149+
image: typedb-ubuntu-20.04 # Ubuntu 20.04 has GLIBC version 2.31 (2020) which we should verify to compile against
150+
dependencies:
151+
- build
152+
command: |
153+
export ARTIFACT_USERNAME=$REPO_TYPEDB_USERNAME
154+
export ARTIFACT_PASSWORD=$REPO_TYPEDB_PASSWORD
155+
bazel run @typedb_dependencies//tool/bazelinstall:remote_cache_setup.sh
156+
bazel run @typedb_dependencies//distribution/artifact:create-netrc
157+
tool/test/start-community-server.sh &&
158+
bazel test //c/tests/integration:test-driver --test_output=errors &&
159+
export TEST_SUCCESS=0 || export TEST_SUCCESS=1
160+
tool/test/stop-community-server.sh
161+
exit $TEST_SUCCESS
162162
163163
test-java-integration:
164164
image: typedb-ubuntu-22.04

RELEASE_TEMPLATE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,8 @@ Documentation: https://typedb.com/docs/drivers/
5757
npm install typedb-driver-http@{version}
5858
```
5959

60+
### C driver
61+
62+
Compiled distributions comprising headers and shared libraries available at: https://cloudsmith.io/~typedb/repos/public-release/packages/?q=name:^typedb-driver-clib+version:{version}
63+
6064
{ release notes }

c/README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# TypeDB C Driver
22
The TypeDB C driver provides C bindings to the rust driver.
33
It also serves as the base on which the other wrapper drivers are built.
4+
It is not very ergonomic to be used directly as a C driver. That is future work.
45

56
## Usage
67
The driver is distributed as an archive containing the headers & a shared library.
@@ -22,16 +23,19 @@ Code examples can be found in the [integration tests](https://github.com/typedb/
2223

2324
Functions parameters & return values are either primitives or pointers to opaque structs, e.g.:
2425
```c
25-
Driver *driver_open_core(const char *address);
26+
struct TypeDBDriver *driver_open(const char *address,
27+
const struct Credentials *credentials,
28+
const struct DriverOptions *driver_options);
2629
```
2730
2831
These pointers are then used for further operations:
2932
```c
3033
char* dbName = "hello";
31-
Driver *driver = driver_open_core("127.0.0.1:1729");
32-
DatabaseManager* databaseManager = database_manager_new(driver);
33-
databases_create(databaseManager, dbName);
34-
Database* database = databases_get(databaseManager, dbName);
34+
DriverOptions* options = driver_options_new(false, NULL);;;
35+
Credentials* creds = credentials_new(username, password);
36+
TypeDBDriver* driver = driver_open(address, creds, options);
37+
databases_create(driver, dbName);
38+
Database* database = databases_get(driver, dbName);
3539
char* gotName = database_name(database);
3640
assert(0 == strcmp(gotName, dbName));
3741
...
@@ -46,7 +50,6 @@ Types which have `*_close` methods will be freed on close.
4650
...
4751
string_free(gotName);
4852
database_close(database);
49-
database_manager_drop(databaseManager);
5053
driver_close(connection);
5154
```
5255
@@ -68,7 +71,7 @@ if (check_error()) {
6871
Iterators can be forwarded with the `*_iterator_next` method,
6972
which returns `NULL` when the end has been reached.
7073
```c
71-
DatabaseIterator* it = databases_all(databaseManager);
74+
DatabaseIterator* it = databases_all(driver);
7275
Database* database = NULL;
7376
while (NULL != (database = database_iterator_next(it))) {
7477
...

c/tests/assembly/test.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <typedb_driver.h>
2424

2525
const char* TYPEDB_CORE_ADDRESS = "127.0.0.1:1729";
26+
const char* TYPEDB_CORE_USERNAME = "admin";
27+
const char* TYPEDB_CORE_PASSWORD = "password";
2628
const char* DRIVER_LANG = "c";
2729

2830

@@ -40,34 +42,42 @@ bool check_error_may_print(const char* filename, int lineno) {
4042
}
4143

4244
#define FAILED() check_error_may_print(__FILE__, __LINE__)
45+
TypeDBDriver* driver_open_for_tests(const char* address, const char* username, const char* password) {
46+
DriverOptions* options = NULL;
47+
Credentials* creds = credentials_new(username, password);
48+
if (check_error_may_print(__FILE__, __LINE__)) goto cleanup;
49+
options = driver_options_new(false, NULL);;
50+
if (check_error_may_print(__FILE__, __LINE__)) goto cleanup;
51+
TypeDBDriver* driver = driver_open_with_description(address, creds, options, DRIVER_LANG);
52+
cleanup:
53+
driver_options_drop(options);
54+
credentials_drop(creds);
55+
56+
return driver;
57+
}
4358

4459
int main() {
4560
const char databaseName[] = "test_assembly_clib";
4661

47-
Connection* connection = NULL;
48-
DatabaseManager* databaseManager = NULL;
62+
TypeDBDriver* driver = NULL;
4963

5064
bool success = false;
5165

52-
connection = driver_open_core(TYPEDB_CORE_ADDRESS, DRIVER_LANG);
53-
if (FAILED()) goto cleanup;
54-
55-
databaseManager = database_manager_new(connection);
66+
driver = driver_open_for_tests(TYPEDB_CORE_ADDRESS, TYPEDB_CORE_USERNAME, TYPEDB_CORE_PASSWORD);
5667
if (FAILED()) goto cleanup;
5768

58-
databases_create(databaseManager, databaseName);
69+
databases_create(driver, databaseName);
5970
if (FAILED()) goto cleanup;
6071

61-
if (!databases_contains(databaseManager, databaseName)) {
72+
if (!databases_contains(driver, databaseName)) {
6273
fprintf(stderr, "databases_contains(\'%s\') failed\n", databaseName);
6374
goto cleanup;
6475
}
6576

6677
success = true;
6778
cleanup:
6879
check_error_may_print(__FILE__, __LINE__);
69-
database_manager_drop(databaseManager);
70-
driver_close(connection);
80+
driver_close(driver);
7181

7282
printf("Success: %s\n", success ? "true" : "false");
7383
return success ? 0 : 1;

c/tests/integration/common.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include "common.h"
2424

2525
const char* TYPEDB_CORE_ADDRESS = "127.0.0.1:1729";
26+
const char* TYPEDB_CORE_USERNAME = "admin";
27+
const char* TYPEDB_CORE_PASSWORD = "password";
2628
const char* DRIVER_LANG = "c";
2729

2830
bool check_error_may_print(const char* filename, int lineno) {
@@ -38,9 +40,27 @@ bool check_error_may_print(const char* filename, int lineno) {
3840
} else return false;
3941
}
4042

41-
void delete_database_if_exists(DatabaseManager* databaseManager, const char* name) {
42-
if (NULL != databaseManager && databases_contains(databaseManager, name)) {
43-
Database* database = databases_get(databaseManager, name);
44-
database_delete(database);
43+
void delete_database_if_exists(TypeDBDriver* driver, const char* name) {
44+
if (driver == NULL) return;
45+
bool contains = databases_contains(driver, name);
46+
if (check_error_may_print(__FILE__, __LINE__)) return;
47+
if (contains) {
48+
const Database* db = databases_get(driver, name);
49+
if (check_error_may_print(__FILE__, __LINE__)) return;
50+
database_delete(db);
4551
}
4652
}
53+
54+
TypeDBDriver* driver_open_for_tests(const char* address, const char* username, const char* password) {
55+
DriverOptions* options = NULL;
56+
Credentials* creds = credentials_new(username, password);
57+
if (check_error_may_print(__FILE__, __LINE__)) goto cleanup;
58+
options = driver_options_new(false, NULL);;
59+
if (check_error_may_print(__FILE__, __LINE__)) goto cleanup;
60+
TypeDBDriver* driver = driver_open_with_description(address, creds, options, DRIVER_LANG);
61+
cleanup:
62+
driver_options_drop(options);
63+
credentials_drop(creds);
64+
65+
return driver;
66+
}

c/tests/integration/common.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818
*/
1919

2020
extern const char* TYPEDB_CORE_ADDRESS;
21+
extern const char* TYPEDB_CORE_USERNAME;
22+
extern const char* TYPEDB_CORE_PASSWORD;
2123

2224
bool check_error_may_print(const char* filename, int lineno);
2325

24-
void delete_database_if_exists(DatabaseManager* databaseManager, const char* name);
26+
TypeDBDriver* driver_open_for_tests(const char* address, const char* username, const char* password);
27+
28+
void delete_database_if_exists(TypeDBDriver* driver, const char* name);

0 commit comments

Comments
 (0)