I'm looking for a way to test if my application can survive if the database it connects to goes down and back up again. In which case the expected behaviour of the application would be to first throw an exception and then reconnect successfully once the database is up.
I would like to do so in an automated integration test (so manually powering off/on the database and see how the app behaves is out of question).
Connecting to an in-memory database is an option but this will devalue the test somewhat since the prod code and test code wont run against exactly the same db and drivers, so not ideal.
Another option would be for the test to trigger a process which would cutoff the connection between the database and the app for a few seconds (not sure how to do that).
Any other ideas ?
Technical stack is Java with Spring (jdbc templates).
I think you can try to supply with incorrect db log in information to simulate the connection loss
If you are looking at killing the connection, depending on your setup you could create a batch script to disable your network adapter, and another switch it back on again once you are ready
This might help
How can I write a batch file to toggle my network adapters?
and you can use this to call the script
How do I run a batch file from my Java Application?
Related
I have a web server which is presenting some data from a Cloudera cluster. The data are stored on HBase and the cluster is secured with Kerberos. When I try to perform a get, the server hangs without logging any error.
So far I've tried:
Launching the webserver from command line after a kinit (the server is just for testing purpose, so log-in duration and complex procedures to start it are not an issue)
The runAs approach described in here, both with and without the configuration file import from this answer.
The CLASSPATH configuration approach described here
Global authentication with UserGroupInformation.loginUserFromKeytab (with and without all the configurations from point 2 and 3)
I've executed all the gets from hbase shell after kiniting with the web server's user and they work in reasonable time (less than a second, while the last time I left the connection open the server didn't respond in over an hour), so it's not a performance or authorization issue. Inside the same web server, with every configuration listed, I'm able to perform other actions, like connecting to HBase and getting the table instances.
I've also checked the logs from Kerberos, HBase and my web server and none of them presents any error. In fact, I'm pretty much afraid that the authorization works, but it just gets stuck in some loop during the get.
UPDATES: After more testing, I've verified that there is a user set right before the call to HBase's API. Also, I've checked and no calls are made to HBase. So this is not an authentication problem, but something else. Did anybody have the same problem?
I have a Spring Boot app (jar file) that is running on Windows server and is used to sync data between some tables in a database and other parts of infrastructure (consumer apps via ActiveMQ).
It is crucial to have it running 24/7 without any downtime (or with very little).
I am currently trying to find the best way to do this as our current solution is to run multiple instances of the same app and define one to be active and ping it continuously (via an entry in database where it writes every 15 seconds), while other instances are just running and do nothing (inactive state, cause lock is taken). If an active instance has stopped to update lock entry (freeze or crashed) in database one of the available instances will take its place and start to handle data.
I have a feeling, that it is not so flexible solution, especially when I need to prepare different part of my code to check lock entry and sync all those instances. It adds complexity to the code and I want to avoid it.
Is there any better solution? Plugins, implementation pattern or tools?
PS:
I read about health endpoints that are available in a SpringBootApplication and think that it can help me somehow (ping\check them from some other Watchdog software\tool, maybe?), but don't know how.
In case of a crash you still have a delay of 15 seconds while a request can fail
I would go with a zuul router from netflix (open source)
It will balance the load between instances and will retry your request on another instance if the first call has failed
I'm pretty sure it's already done but use windows services to restart instance in case of hard crash
I have created a java application that is inserting data to a mysql database. Under some conditions, i need to post some of these data via email, using a java application that I will write as well.
My problem is that i am not sure how i should implement this.
From what I understand, I could use a UDF inside MySql to execute a java application, for which there are many against opinions into using it. Let alone that both the database and the mail client application will reside in a VM that i dont have admin access, and dont want to install anything that neither me nor the admin knows.
My other alternative, that I can think of, is to set up the mail client (or some other application), to run every minute just to check for newly inserted data. Is this a better aproach? Isn't it going to use resources for doing almost nothing. At the moment the VM might not be heavily loaded, but i have no idea how many applications there might end up running on the same machine.
Is there any other alternative i should consider using?
You also need to consider the speed of internet, database server load, system resources. If you have enough memory and less load to insert data in databases or database load is not so much then you can approach this by cron setup. For linux call a script for every 5 minutes. The script perform the following-
1. Fetch unread Emails as files
3. Perfrom shell script to read needed data.
3. write data to mysql
4. Delete the email
If you have heavy loaded system then wise you need to do this once or twice in an hour or may vary.
I'm using the H2 Database Engine for java to have access to a database in my java programs. I developed many java programs which use the same database. The problem is that whenever I start such a program while another is already running it can't access the database because it is opened by the other program.
Is there a way to let both programs have a connection to the database? Whenever one program has to query the database the database should execute the query. In case it is executing the query of the other program the query should be executed directly after the query of the other program. Since my queries don't take long time the user wouldn't recognize that his program has to wait for a moment and everything would be fine.
H2 server mode is what you want.
You need to have at least started the server this way for example:
org.h2.tools.Server.createTcpServer().start();
Then replace all the jdbc url with jdbc:h2://yourhost/yourdb, keeping in mind yourdb.h2.db will be located where the server was started. I strongly advise not to use absolute path in your jdbc url, as it will give away the database path in case of hacking.
Last but not least: using the server mode for all has a performance penalty. You might want to use mixed mode so that the 1st client will have almost embedded performances.
To do this, just replace for this client the url with jdbc:h2:yourdb;AUTO_SERVER=TRUE. You could decide to use the same url for all clients as well: the 1st one to connect will be using embedded mode, the other clients will be using tcp performance.
Note that if you're using H2 > 1.4.*, you need to give absolute or relative path like this: jdbc:h2:./yourdb;AUTO_SERVER=TRUE. Note the ./
We are in the process of creating a training mode for our ColdFusion (9) sites.
The system will allow our users, after logging in, to switch from production mode to training mode by clicking on a link.
When they switch, the data-sources will be switched allowing the data to be safely modified.
We are also going to implement a test SMTP server, using the SubEthaSMTP Java project, in order to capture the emails that are sent from the training mode and display them to the user in a web page.
We can launch the SMTP server as a stand alone process or service without much trouble.
The nicer solution would be to launch server as part of the ColdFuson runtime at the point that the user switches to training mode.
We would create a true Java thread that would persist on a Server level scope for the length of any training sessions and then some arbitrary time out period. If the server times out and a new training session is initiated we would initiate a new SMTP server.
My essential question is, therefore, is it a bad idea to run an ongoing thread in the ColdFusion runtime this way?
I can't see a problem with doing this, although you ought to test to see what resources SubEthaSMTP uses and make sure it's not going to cause you issues. It looks to have minimal dependencies (essentially just SLF4J, which ColdFusion 9 & 10 already provide)
From the example page it looks to be pretty easy to set up and drop into a long-running scope. I think you're right to pick the server scope, as you may have problems using application or anything more volatile, as there'll be a situation where application scope would timeout and be reset, but you'd loose all references to the Mail Server instance.
Please update the post with your findings, as I'd be interested in seeing what you find.