can't get `lein test` to work

203 views
Skip to first unread message

Gregg Williams

unread,
Apr 23, 2012, 2:50:10 AM4/23/12
to clj-record-dev
Hi. I'm new to clj-record and am trying to get the built-in lein test
to work. Here's what I've done:

* I have a fresh download of clj-record 1.1.1.
* I've put all the jar files for Derby into the project's lib
directory.
* In /Users/gw/tech/clojurestuff/cljprojects/clj-record/test/
clj_record/test_model/config.clj, I uncommented the code for using
Derby.
* After running `lein deps`, the lib directory now contains the file
java.jdbc-0.1.1.jar.

However, when I try to run `lein test` with the current directory
being the project's directory (clj-record), I get the output at the
end of this message. What am I doing wrong? Thanks.

-- Gregg

=== output begins ===

23:34 clj-record $lein test

Testing clj-record.associations-test

ERROR in (has-many-custom-fk-and-model)
(NativeConstructorAccessorImpl.java:-2)
Uncaught exception, not in assertion.
expected: nil
actual: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
Communications link failure

The last packet sent successfully to the server was 0 milliseconds
ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0
(NativeConstructorAccessorImpl.java:-2)
sun.reflect.NativeConstructorAccessorImpl.newInstance
(NativeConstructorAccessorImpl.java:39)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance
(DelegatingConstructorAccessorImpl.java:27)
java.lang.reflect.Constructor.newInstance (Constructor.java:513)
com.mysql.jdbc.Util.handleNewInstance (Util.java:411)
com.mysql.jdbc.SQLError.createCommunicationsException
(SQLError.java:1116)
com.mysql.jdbc.MysqlIO.<init> (MysqlIO.java:344)
com.mysql.jdbc.ConnectionImpl.coreConnect (ConnectionImpl.java:
2333)
com.mysql.jdbc.ConnectionImpl.connectOneTryOnly
(ConnectionImpl.java:2370)
com.mysql.jdbc.ConnectionImpl.createNewIO (ConnectionImpl.java:
2154)
com.mysql.jdbc.ConnectionImpl.<init> (ConnectionImpl.java:792)
com.mysql.jdbc.JDBC4Connection.<init> (JDBC4Connection.java:47)
sun.reflect.NativeConstructorAccessorImpl.newInstance0
(NativeConstructorAccessorImpl.java:-2)
sun.reflect.NativeConstructorAccessorImpl.newInstance
(NativeConstructorAccessorImpl.java:39)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance
(DelegatingConstructorAccessorImpl.java:27)
java.lang.reflect.Constructor.newInstance (Constructor.java:513)
com.mysql.jdbc.Util.handleNewInstance (Util.java:411)
com.mysql.jdbc.ConnectionImpl.getInstance (ConnectionImpl.java:
381)
com.mysql.jdbc.NonRegisteringDriver.connect
(NonRegisteringDriver.java:305)
java.sql.DriverManager.getConnection (DriverManager.java:582)
java.sql.DriverManager.getConnection (DriverManager.java:154)
clojure.java.jdbc.internal$get_connection.invoke (internal.clj:
166)
clojure.java.jdbc.internal$with_connection_STAR_.invoke
(internal.clj:184)
clj_record.associations_test/fn (associations_test.clj:36)
clojure.test$test_var$fn__6484.invoke (test.clj:693)
clojure.test$test_var.invoke (test.clj:693)
clojure.test$test_all_vars$fn__6488$fn__6495.invoke (test.clj:709)
clojure.test$default_fixture.invoke (test.clj:663)
clojure.test$test_all_vars$fn__6488.invoke (test.clj:709)
clojure.test$default_fixture.invoke (test.clj:663)
clojure.test$test_all_vars.invoke (test.clj:705)
clojure.test$test_ns.invoke (test.clj:728)
clojure.core$map$fn__3811.invoke (core.clj:2432)
clojure.lang.LazySeq.sval (LazySeq.java:42)
clojure.lang.LazySeq.seq (LazySeq.java:60)
clojure.lang.Cons.next (Cons.java:39)
clojure.lang.RT.boundedLength (RT.java:1607)
clojure.lang.RestFn.applyTo (RestFn.java:130)
clojure.core$apply.invoke (core.clj:602)
clojure.test$run_tests.doInvoke (test.clj:743)
clojure.lang.RestFn.applyTo (RestFn.java:137)
clojure.core$apply.invoke (core.clj:600)
user$eval33$fn__45.invoke (NO_SOURCE_FILE:1)
user$eval33.invoke (NO_SOURCE_FILE:1)
clojure.lang.Compiler.eval (Compiler.java:6465)
clojure.lang.Compiler.eval (Compiler.java:6455)
clojure.lang.Compiler.eval (Compiler.java:6431)
clojure.core$eval.invoke (core.clj:2795)
clojure.main$eval_opt.invoke (main.clj:296)
clojure.main$initialize.invoke (main.clj:315)
clojure.main$null_opt.invoke (main.clj:348)
clojure.main$main.doInvoke (main.clj:426)
clojure.lang.RestFn.invoke (RestFn.java:421)
clojure.lang.Var.invoke (Var.java:405)
clojure.lang.AFn.applyToHelper (AFn.java:163)
clojure.lang.Var.applyTo (Var.java:518)
clojure.main.main (main.java:37)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect (PlainSocketImpl.java:-2)
java.net.PlainSocketImpl.doConnect (PlainSocketImpl.java:351)
java.net.PlainSocketImpl.connectToAddress (PlainSocketImpl.java:
213)
java.net.PlainSocketImpl.connect (PlainSocketImpl.java:200)
java.net.SocksSocketImpl.connect (SocksSocketImpl.java:432)
java.net.Socket.connect (Socket.java:529)
java.net.Socket.connect (Socket.java:478)
java.net.Socket.<init> (Socket.java:375)
java.net.Socket.<init> (Socket.java:218)
com.mysql.jdbc.StandardSocketFactory.connect
(StandardSocketFactory.java:257)
com.mysql.jdbc.MysqlIO.<init> (MysqlIO.java:294)
com.mysql.jdbc.ConnectionImpl.coreConnect (ConnectionImpl.java:
2333)
com.mysql.jdbc.ConnectionImpl.connectOneTryOnly
(ConnectionImpl.java:2370)
com.mysql.jdbc.ConnectionImpl.createNewIO (ConnectionImpl.java:
2154)
com.mysql.jdbc.ConnectionImpl.<init> (ConnectionImpl.java:792)
com.mysql.jdbc.JDBC4Connection.<init> (JDBC4Connection.java:47)
sun.reflect.NativeConstructorAccessorImpl.newInstance0
(NativeConstructorAccessorImpl.java:-2)
sun.reflect.NativeConstructorAccessorImpl.newInstance
(NativeConstructorAccessorImpl.java:39)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance
(DelegatingConstructorAccessorImpl.java:27)
java.lang.reflect.Constructor.newInstance (Constructor.java:513)
com.mysql.jdbc.Util.handleNewInstance (Util.java:411)
com.mysql.jdbc.ConnectionImpl.getInstance (ConnectionImpl.java:
381)
com.mysql.jdbc.NonRegisteringDriver.connect
(NonRegisteringDriver.java:305)
java.sql.DriverManager.getConnection (DriverManager.java:582)
java.sql.DriverManager.getConnection (DriverManager.java:154)
clojure.java.jdbc.internal$get_connection.invoke (internal.clj:
166)
clojure.java.jdbc.internal$with_connection_STAR_.invoke
(internal.clj:184)
clj_record.associations_test/fn (associations_test.clj:36)
clojure.test$test_var$fn__6484.invoke (test.clj:693)
clojure.test$test_var.invoke (test.clj:693)
clojure.test$test_all_vars$fn__6488$fn__6495.invoke (test.clj:709)
clojure.test$default_fixture.invoke (test.clj:663)
clojure.test$test_all_vars$fn__6488.invoke (test.clj:709)
clojure.test$default_fixture.invoke (test.clj:663)
clojure.test$test_all_vars.invoke (test.clj:705)
clojure.test$test_ns.invoke (test.clj:728)
clojure.core$map$fn__3811.invoke (core.clj:2432)
clojure.lang.LazySeq.sval (LazySeq.java:42)
clojure.lang.LazySeq.seq (LazySeq.java:60)
clojure.lang.Cons.next (Cons.java:39)
clojure.lang.RT.boundedLength (RT.java:1607)
clojure.lang.RestFn.applyTo (RestFn.java:130)
clojure.core$apply.invoke (core.clj:602)
clojure.test$run_tests.doInvoke (test.clj:743)
clojure.lang.RestFn.applyTo (RestFn.java:137)
clojure.core$apply.invoke (core.clj:600)
user$eval33$fn__45.invoke (NO_SOURCE_FILE:1)
user$eval33.invoke (NO_SOURCE_FILE:1)
clojure.lang.Compiler.eval (Compiler.java:6465)
clojure.lang.Compiler.eval (Compiler.java:6455)
clojure.lang.Compiler.eval (Compiler.java:6431)
clojure.core$eval.invoke (core.clj:2795)
clojure.main$eval_opt.invoke (main.clj:296)
clojure.main$initialize.invoke (main.clj:315)
clojure.main$null_opt.invoke (main.clj:348)
clojure.main$main.doInvoke (main.clj:426)
clojure.lang.RestFn.invoke (RestFn.java:421)
clojure.lang.Var.invoke (Var.java:405)
clojure.lang.AFn.applyToHelper (AFn.java:163)
clojure.lang.Var.applyTo (Var.java:518)
clojure.main.main (main.java:37)

ERROR in (has-many-creates-a-find-function)
(NativeConstructorAccessorImpl.java:-2)
Uncaught exception, not in assertion.
expected: nil
actual: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
Communications link failure

The last packet sent successfully to the server was 0 milliseconds
ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0
(NativeConstructorAccessorImpl.java:-2)
sun.reflect.NativeConstructorAccessorImpl.newInstance
(NativeConstructorAccessorImpl.java:39)

=== output truncated here; end of message ===

Gregg Williams

unread,
Apr 23, 2012, 4:44:50 PM4/23/12
to clj-rec...@googlegroups.com

After having reread the project page for clj-record, I realized I had to first *create* the test database. Trying to do this, I get the following result:

-----
lein> reset-db
java.io.FileNotFoundException: Could not locate clojure/java/jdbc__init.class or clojure/java/jdbc.clj on classpath:  (core.clj:1)
lein>
-----

However, java.jdbc-0.1.1.jar is in the lib directory, which is where `lein deps` put it and where I would expect it to be.

I'm sure I haven't configured something that needs configuring--possibly Derby itself. Do I need to set any Derby-related environment variables? (I'm on Mac OS X, by the way, and know how to change my .bash_profile file.) Or would Leiningen take care of that?

About Derby: it isn't available through clojars.com, so I just dumped all the Derby distribution jars in the project's lib directory. I know that's not optimal, but I've done that before and it worked.

Again, thanks for any suggestions you might have.

Daniel Renfer

unread,
Apr 23, 2012, 5:12:16 PM4/23/12
to clj-rec...@googlegroups.com
It's been a while since I looked into the clj-record code base, but
based on your error, it looks like something is still trying to access
the mysql db.

Most likely, one of the tests has been hard-coded towards that server.

John D. Hume

unread,
Apr 24, 2012, 7:11:45 AM4/24/12
to clj-rec...@googlegroups.com
I switched from Derby to MySQL for tests before 1.0.0, but I forgot to
change the README. Sorry about that. Will update momentarily.

That likely does not explain your error message though. Looking into it.

On Mon, Apr 23, 2012 at 4:44 PM, Gregg Williams <gre...@innerpaths.net> wrote:
>

--
http://elhumidor.blogspot.com/
http://www.intentmedia.com/jobs

John D. Hume

unread,
Apr 24, 2012, 7:30:31 AM4/24/12
to clj-rec...@googlegroups.com
My guess is that something has changed with the way leiningen wants
extensions defined. In the meantime, you can do the following:

# create the test database. This assumes you have mysql running.
echo "create database clj_record_test" | mysql -uroot
# run a project repl
lein repl
# then inside the repl:
(require 'clj-record.test-helper)
(clj-record.test-helper/reset-db)

If you want to test with a different database, comment and uncomment
in test/clj_record/test_model/config.clj. Also note that's where db
credentials live.

John D. Hume

unread,
Apr 24, 2012, 7:56:44 AM4/24/12
to clj-rec...@googlegroups.com
On Tue, Apr 24, 2012 at 7:30 AM, John D. Hume <duelin....@gmail.com> wrote:
> My guess is that something has changed with the way leiningen wants
> extensions defined.

There was a quoting mistake in the definition of reset-db. It's fixed
now. Please let me know if this now works for you.

Gregg Williams

unread,
Apr 24, 2012, 12:19:51 PM4/24/12
to clj-rec...@googlegroups.com
Thanks for looking into this!

I started by making sure that MySQL was running, wiping out my old directory, downloading your new version from Github, and running `lein deps`. When I ran `lein reset-db`, I got the error at the bottom of this reply.

I then tried the workaround you listed in a previous post in this thread. Once I did that, `lein test` ran perfectly!

Thanks again. My next step is duplicating my success with Derby (which I want to use as my db so I can embed it in my Clojure app and deliver a one-file solution).

John D. Hume

unread,
Apr 24, 2012, 12:39:48 PM4/24/12
to clj-rec...@googlegroups.com

I think you forgot to paste the error. If it's more than a few lines, could you put it on gist, pastie, or similar instead of putting it right in the message? Can you also run lein -v to show what version of leiningen you're running? Thanks.

-- typed with my thumbs

Gregg Williams

unread,
Apr 26, 2012, 1:29:40 AM4/26/12
to clj-rec...@googlegroups.com
Hi--I couldn't find how to delete the database, so I found the actual file clj_record_test and deleted that.

When I attempted to run `lein reset-db`, I *did* get error output. I put it at https://gist.github.com/2496152 . I hope this helps!

--Gregg

PS: I'm running lein 1.62.  --gw

John D. Hume

unread,
Apr 26, 2012, 7:42:25 AM4/26/12
to clj-rec...@googlegroups.com
On Thu, Apr 26, 2012 at 1:29 AM, Gregg Williams <gre...@innerpaths.net> wrote:
> Hi--I couldn't find how to delete the database, so I found the actual file
> clj_record_test and deleted that.
>
> When I attempted to run `lein reset-db`, I *did* get error output. I put it
> at https://gist.github.com/2496152 . I hope this helps!

As I said, you need to create the database yourself, so this error is
expected if you've deleted it. (The SQL for that, incidentally, would
be `DROP DATABASE clj_record_test`, or from the shell `echo "drop
database clj_record_test" | mysql -uroot`.)

Note that touching MySQL's data files directly may land you in a bad
state. I'd recommend avoiding that. Their documentation is pretty
helpful:
http://dev.mysql.com/doc/refman/5.5/en/sql-syntax-data-definition.html
Reply all
Reply to author
Forward
0 new messages