Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigated issue 261 #447

Merged
merged 35 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7fa01b2
Added examples/poly-rcf.
Mar 3, 2024
e6a44e9
Fixed some problems + added the monolith project.
Mar 3, 2024
bdd6e30
Removed unused namespace.
Mar 3, 2024
039432f
Removed empty line.
Mar 3, 2024
fb0d3f2
Fixed formatting.
Mar 3, 2024
35149b6
Renamed from mybase to emptybase.
Mar 3, 2024
49ebc52
Updated comment.
Mar 3, 2024
a9affa3
Use the local poly tool.
Mar 3, 2024
b2b61e4
Removed the :poly alias (this is not a Polylith workspace).
Mar 3, 2024
9eebec1
Changed from repo to workspace.
Mar 3, 2024
dab4b89
Use latest version of the poly tool.
Mar 3, 2024
bfed2ac
Removed text that can be found in the PR.
Mar 3, 2024
19e4496
Removed blank line.
Mar 3, 2024
405d619
Removed the logo image.
Mar 3, 2024
758d172
Updated the instructions.
Mar 3, 2024
449ba84
Minor change.
Mar 3, 2024
2ea9859
Minor change.
Mar 3, 2024
9411c71
Moved code to the :dev alias.
Mar 4, 2024
d503ccd
Removed the "src" directory from the test paths.
Mar 4, 2024
ac12779
Formatting change.
Mar 4, 2024
fd216ba
Added examples/poly-rcf/mix-src-and-test
Mar 5, 2024
39cdfbe
Removed mix-src-and-test.
Mar 6, 2024
92d6338
Show how to execute the test from development.
Mar 6, 2024
7c68af3
Rearranged the deps.
Mar 6, 2024
c52e674
Rearranged the deps + added dependency to org.clojure/clojure.
Mar 6, 2024
9e07246
Cleaned up deps.
Mar 6, 2024
299c54b
Removed "src" from :test > :extra-paths.
Mar 6, 2024
6a6041c
Add hyperfiddle/rcf and slf4j src deps + test path.
Mar 6, 2024
246d501
Renamed deps key.
Mar 6, 2024
de753d1
Added config files that mimics the poly-261 and rcf project files (if…
Mar 6, 2024
00babd4
Updated text.
Mar 6, 2024
dbf7264
Minor update.
Mar 6, 2024
e01192f
Update the text.
Mar 6, 2024
d8cb1f5
We can run both projects using the external test runner.
Mar 6, 2024
86e84b4
0.2.20-SNAPSHOT #6.
Mar 6, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
reflected in:
* https://github.com/imrekoszo/polylith-kaocha
* https://github.com/seancorfield/polylith-external-test-runner
and any others that get built by the community."
and any others that get built by the community."
[{:keys [workspace project]}]
(let [{:keys [bases components]} workspace
{:keys [name bricks-to-test projects-to-test namespaces paths]} project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
(def minor 2)
(def patch 20)
(def revision SNAPSHOT) ;; Set to SNAPSHOT or RELEASE.
(def snapshot 5) ;; Increase by one for every snapshot release, or set to 0 if a release.
(def snapshot 6) ;; Increase by one for every snapshot release, or set to 0 if a release.
;; Also update :snapshot-version: at the top of readme.adoc.
(def snapshot? (= SNAPSHOT revision))

Expand All @@ -37,7 +37,7 @@

(def tool (if system/extended? "polyx" "poly"))

(def date "2024-03-02")
(def date "2024-03-06")

;; Execute 'poly doc version' to see when different changes was introduced.
(def api-version {:breaking 1, :non-breaking 0})
Expand Down
3 changes: 3 additions & 0 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
"components/ws-explorer/test"
"bases/poly-cli/test"
"projects/poly/test"]}
; :extra-deps {io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"}}
; :main-opts ["-m" "cognitect.test-runner"]
; :exec-fn cognitect.test-runner.api/test}

;; Any sha
:polys {:main-opts ["-m" "polylith.clj.core.poly-cli.core"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{:hooks
{:analyze-call
{next.jdbc/with-transaction
hooks.com.github.seancorfield.next-jdbc/with-transaction}}
:lint-as {next.jdbc/on-connection clojure.core/with-open}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(ns hooks.com.github.seancorfield.next-jdbc
(:require [clj-kondo.hooks-api :as api]))

(defn with-transaction
"Expands (with-transaction [tx expr opts] body)
to (let [tx expr] opts body) per clj-kondo examples."
[{:keys [:node]}]
(let [[binding-vec & body] (rest (:children node))
[sym val opts] (:children binding-vec)]
(when-not (and sym val)
(throw (ex-info "No sym and val provided" {})))
(let [new-node (api/list-node
(list*
(api/token-node 'let)
(api/vector-node [sym val])
opts
body))]
{:node new-node})))
41 changes: 41 additions & 0 deletions examples/poly-rcf/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
**/classes
**/target
**/.artifacts
**/.cpcache
**/.DS_Store
**/.gradle

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/shelf
.idea/**/statistic.xml
.idea/dictionaries/**
.idea/libraries/**

# File-based project format
*.iws
*.ipr

# Cursive Clojure plugin
.idea/replstate.xml
*.iml

/example/example/**
artifacts
projects/**/pom.xml

# nrepl
.nrepl-port

# clojure-lsp
.lsp/.cache

# clj-kondo
.clj-kondo/.cache

# Calva VS Code Extension
.calva/output-window/output.calva-repl

.portal
12 changes: 12 additions & 0 deletions examples/poly-rcf/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"calva.replConnectSequences": [
{
"projectType": "deps.edn",
"name": "poly-rcf",
"cljsType": "none",
"menuSelections": {
"cljAliases": ["dev", "test", "+default"]
}
}
]
}
5 changes: 5 additions & 0 deletions examples/poly-rcf/bases/empty/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
;; I had to add hyperfiddle/rcf + slf4j, for the tests to run.
{:paths ["src"]
:deps {com.hyperfiddle/rcf {:mvn/version "20220405"}}
:aliases {:test {:extra-paths ["test"]
:extra-deps {org.slf4j/slf4j-simple {:mvn/version "2.0.0-beta1"}}}}}
1 change: 1 addition & 0 deletions examples/poly-rcf/bases/empty/src/poly_rcf/empty/core.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(ns poly-rcf.empty.core)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(ns poly-rcf.empty.core-test
(:require [clojure.test :as test :refer :all]))

(deftest dummy-test
(is (= 1 1)))
4 changes: 4 additions & 0 deletions examples/poly-rcf/bases/rcf/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{:paths ["src"]
:deps {com.hyperfiddle/rcf {:mvn/version "20220405"}}
:aliases {:test {:extra-paths ["test"] ;; We don't need "src" here.
:extra-deps {org.slf4j/slf4j-simple {:mvn/version "2.0.0-beta1"}}}}}
8 changes: 8 additions & 0 deletions examples/poly-rcf/bases/rcf/src/poly_rcf/rcf/config.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(ns poly-rcf.rcf.config)
;; A master configuration file.
;; Can be overriden with configuration files down in the classpath,
;; environment variables, and system properties

{:dre {}
:sentry {:dsn ""
:environment ""}}
8 changes: 8 additions & 0 deletions examples/poly-rcf/bases/rcf/src/poly_rcf/rcf/src_ns.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(ns poly-rcf.rcf.src-ns
(:require [hyperfiddle.rcf :refer [tests]]))

(tests

(+ 1 1) := 2

)
11 changes: 11 additions & 0 deletions examples/poly-rcf/bases/rcf/test/poly_rcf/rcf/sample2_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(ns poly-rcf.rcf.sample2-test
(:require [clojure.test :as t :refer [deftest is testing]]))

(deftest math-works
(testing "basic addition and subtraction"
(is (= 42 (+ 40 2)))
(is (= 42 (- 44 2)))))

(deftest ^:integration test-i
(is (= 1 1)))

8 changes: 8 additions & 0 deletions examples/poly-rcf/bases/rcf/test/poly_rcf/rcf/sample_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(ns poly-rcf.rcf.sample-test
(:require [hyperfiddle.rcf :refer [tests]]))

(tests

(= 1 1) := true

)
8 changes: 8 additions & 0 deletions examples/poly-rcf/bases/rcf/test/poly_rcf/rcf/test_ns.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(ns poly-rcf.rcf.test-ns
(:require [hyperfiddle.rcf :refer [tests]]))

(tests

(+ 1 1) := 2

)
9 changes: 9 additions & 0 deletions examples/poly-rcf/components/sqldb/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{:paths ["src"]
:deps {com.github.seancorfield/next.jdbc {:mvn/version "1.3.874"}
com.github.seancorfield/honeysql {:mvn/version "2.4.1026"}
com.zaxxer/HikariCP {:mvn/version "5.0.1"
:exclusions [org.slf4j/slf4j-api]}
org.clojure/tools.logging {:mvn/version "1.2.4"}}
:aliases {:test {:extra-paths ["test" "src"] ;; Adding src makes poly tool discover RCF tests under src/
:extra-deps {com.h2database/h2 {:mvn/version "2.1.214"}
com.stuartsierra/component {:mvn/version "1.1.0"}}}}}
57 changes: 57 additions & 0 deletions examples/poly-rcf/components/sqldb/src/poly_rcf/sqldb/core.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
;; Copyright (C) 2022, Doctor Evidence. All rights reserved.

(ns poly-rcf.sqldb.core
"SQL DB client impl."
{:authors ["Jozef Wagner"]}
(:require [clojure.tools.logging :refer [info]]
[next.jdbc.connection :as connection])
(:import [com.zaxxer.hikari HikariDataSource]))

(defn get-connection
[sqlconn]
(or (:hikari-datasource sqlconn) sqlconn))

;;; SQLDB

;;; System Component

(defn start-component
[new-sqldb]
(info "Create component with db" new-sqldb)
(let [db-spec (:db-spec new-sqldb)
hikari-datasource (connection/->pool HikariDataSource db-spec)]
(assoc new-sqldb
:hikari-datasource hikari-datasource)))

(defn stop-component
[sqldb]
(when-let [^HikariDataSource ds (:hikari-datasource sqldb)]
(when-not (.isClosed ds)
(.close ds)))
(dissoc sqldb :hikari-datasource))

(defn suspend-component
[sqldb]
(info "Suspending SQLDB component")
sqldb)

(defn resume-component
[_new-sqldb suspended-sqldb]
;; TODO: Proper reconnect when cfg changes
(info "Resuming SQLDB component")
suspended-sqldb)

(defn new-component
"Returns new sqldb system component."
[cfg tag]
(let [db-config (get-in cfg [:dre tag])]
(-> db-config
(with-meta {'com.stuartsierra.component/start start-component
'com.stuartsierra.component/stop stop-component
'suspendable.core/suspend suspend-component
'suspendable.core/resume resume-component}))))

(comment

(set! *warn-on-reflection* true))

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(ns poly-rcf.sqldb.interface
(:require [poly-rcf.sqldb.core :as core]))


(defn new-component
"Returns new sqldb system component."
[cfg tag]
(core/new-component cfg tag))
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
(ns poly-rcf.sqldb.interface-test
(:require [clojure.set :as set]
[clojure.test :refer :all]
[clojure.tools.logging :as log]
[com.stuartsierra.component :as component]
[next.jdbc :as jdbc]
[next.jdbc.result-set :as rs]
[poly-rcf.sqldb.interface :as sqldb]))

;; This fails because of https://github.com/polyfy/polylith/issues/261
(deftest new-component-test
"Test component works by starting a system and running a query."
(let [config {:dre {:test {:db-spec {:maximum-pool-size 10
:connection-timeout 30000
:idle-timeout 600000
:validation-timeout 5000
:max-lifetime 1800000
:jdbcUrl "jdbc:h2:mem:semmed"}}}}
sys (component/system-map
:sqldb (sqldb/new-component config :test))
s (component/start-system sys)
sqldb (:sqldb s)
data-source (:hikari-datasource sqldb)
_ (log/info "datasource" sqldb)
;; read table metadata
d (with-open [con (jdbc/get-connection data-source)]
(-> (.getMetaData con) ; produces java.sql.DatabaseMetaData
(.getTables nil nil nil (into-array ["TABLE" "VIEW"]))
(rs/datafiable-result-set con)))
some-tables #{"CONSTANTS" "ENUM_VALUES" "INDEXES"
"INDEX_COLUMNS" "INFORMATION_SCHEMA_CATALOG_NAME"}
all-tables (into #{} (map :TABLE_NAME d))]
;; test that some tables are present in metadata
(is (true? (set/subset? some-tables all-tables)))
(component/stop-system s)))
17 changes: 17 additions & 0 deletions examples/poly-rcf/deps-261.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
;; To test this config, rename the file to deps.edn.
{:aliases {:dev {:extra-paths ["development/src"]
:extra-deps {poly/sqldb {:local/root "components/sqldb"}
poly/empty {:local/root "bases/empty"}

org.clojure/clojure {:mvn/version "1.11.1"}}}

:test {:extra-paths ["bases/rcf/test"
"bases/empty/test"]
:extra-deps {org.clojure/test.check {:mvn/version "1.1.1"}
io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"}}
:main-opts ["-m" "cognitect.test-runner"]
:exec-fn cognitect.test-runner.api/test}

:poly {:main-opts ["-m" "polylith.clj.core.poly-cli.core"]
:jvm-opts ["-Dhyperfiddle.rcf.generate-tests=true"]
:extra-deps {polylith/clj-poly {:local/root "../../projects/poly"}}}}}
16 changes: 16 additions & 0 deletions examples/poly-rcf/deps-rcf.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
;; To test this config, rename the file to deps.edn.
{:aliases {:dev {:extra-paths ["development/src"]
:extra-deps {poly/sqldb {:local/root "components/sqldb"}
poly/rcf {:local/root "bases/rcf"}

org.clojure/clojure {:mvn/version "1.11.1"}}}

:test {:extra-paths ["bases/rcf/test"]
:extra-deps {org.clojure/test.check {:mvn/version "1.1.1"}
io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"}}
:main-opts ["-m" "cognitect.test-runner"]
:exec-fn cognitect.test-runner.api/test}

:poly {:main-opts ["-m" "polylith.clj.core.poly-cli.core"]
:jvm-opts ["-Dhyperfiddle.rcf.generate-tests=true"]
:extra-deps {polylith/clj-poly {:local/root "../../projects/poly"}}}}}
18 changes: 18 additions & 0 deletions examples/poly-rcf/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{:aliases {:dev {:extra-paths ["development/src"]
:extra-deps {poly/sqldb {:local/root "components/sqldb"}
poly/rcf {:local/root "bases/rcf"}
poly/empty {:local/root "bases/empty"}

org.clojure/clojure {:mvn/version "1.11.1"}}}

:test {:extra-paths ["bases/rcf/test"
"bases/empty/test"]}

:poly {:main-opts ["-m" "polylith.clj.core.poly-cli.core"]
:jvm-opts [;; Run RCF tests when loading files in REPL
;; https://github.com/hyperfiddle/rcf#ci
"-Dhyperfiddle.rcf.generate-tests=true"]

:extra-deps {polylith/clj-poly {:local/root "../../projects/poly"}}}}}
;; Add this line to use the external test runner + a row in workspace.edn.
;;io.github.seancorfield/polylith-external-test-runner {:git/tag "v0.4.0" :git/sha "eb954fe" :deps/root "projects/runner"}}}}}
1 change: 1 addition & 0 deletions examples/poly-rcf/development/src/.keep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

17 changes: 17 additions & 0 deletions examples/poly-rcf/monolith/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
;; Run tests with: clojure -A:dev -X:test
{:aliases {:dev {:extra-paths ["src"]
:extra-deps {com.github.seancorfield/next.jdbc {:mvn/version "1.3.874"}
com.github.seancorfield/honeysql {:mvn/version "2.4.1026"}
com.zaxxer/HikariCP {:mvn/version "5.0.1" :exclusions [org.slf4j/slf4j-api]}
org.clojure/tools.logging {:mvn/version "1.2.4"}
org.clojure/clojure {:mvn/version "1.11.1"}}}

;; https://clojure.org/guides/deps_and_cli#test_runner
:test {:extra-paths ["test"]
:extra-deps {com.h2database/h2 {:mvn/version "2.1.214"}
com.stuartsierra/component {:mvn/version "1.1.0"}
org.clojure/test.check {:mvn/version "1.1.1"}
org.slf4j/slf4j-simple {:mvn/version "2.0.0-beta1"}
io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"}}
:main-opts ["-m" "cognitect.test-runner"]
:exec-fn cognitect.test-runner.api/test}}}
1 change: 1 addition & 0 deletions examples/poly-rcf/monolith/src/poly_rcf/empty/core.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(ns poly-rcf.empty.core)
Loading