I'd like configure IndefiniteWaitOneShotStartupCheckStrategy by properties, not using Java class on testcontainer - testcontainers

I need use "Indefinite one shot startup strategy example" by testcontainer.properties.
How could I configure IndefiniteWaitOneShotStartupCheckStrategy using properties?
For real, I'd like to configure this three examples by properties, but I don't know how to do this:
container.withStartupCheckStrategy(
new IndefiniteWaitOneShotStartupCheckStrategy()
);
container.waitingFor(
Wait.forLogMessage("Completed: ALTER PLUGGABLE DATABASE XEPDB1 SAVE STATE", 1)
);
container.withStartupTimeoutSeconds(30);
Reference:
https://www.testcontainers.org/features/startup_and_waits/#indefinite-one-shot-startup-strategy-example

It's not possible for now.
See discussion here: https://github.com/testcontainers/testcontainers-java/discussions/4302

Related

log4j2: How do you create & set level for LevelMatchFilter in Java?

I'm trying to migrate the following Java code to log4j2:
private Filter setupWarningLevelFilter()
{
LevelMatchFilter levelFilter = new LevelMatchFilter();
levelFilter.setLevelToMatch(Level.ERROR.toString());
levelFilter.setAcceptOnMatch(false);
return levelFilter;
}
I have not found an example googling. (XML config won't help since custom appender doesn't recognize it - have to pass filter & layout in to custom appender via Java instead.) I don't understand how to interpret the cryptic apache documentation. I have gone in all the hacking circles I can think of using all kinds of combinations of build(), newBuilder(), etc. to create the LevelMatchFilter.
Related to this problem is a compilation error that appears to not like me importing both
org.apache.logging.log4j.filter.LevelMatchFilter.Builder and org.apache.logging.log4j.layout.PatternLayout.Builder
It gives error for PatternLayout.Builder stating " a type with the same simple name is already defined by the single-type-import of Builder".
Appreciate any insight/examples anyone can offer.

How can I globally set Oracle fetch size in my Scala Play (Anorm) application?

Our DBAs would like me to increase the fetch size from the JDBC's default (10). Is there a way to do this globally via application.conf, JDBC URL or similar?
My DB calls essentially look like
object SomeController extends Controller {
def someMethod(acronym: String) = Action { implicit request =>
DB.withConnection { implicit c =>
val cust = SQL("""select whatever.... where acronym = {acronym}""").on("acronym" -> acronym).apply()
But there's a lot of them over many controllers and methods.
What can be done to have a central setting?
defaultRowPrefresh is an Oracle JDBC driver property than can be set to change from the default of 10 (Table 4-2 Connection Properties Recognized by Oracle JDBC Drivers)
While not explicitly documented, it looks like custom JDBC properties are done under the datasource key (see this and this)
So something like db.default.datasource.defaultRowsPrefetch="100" should work.
After some searching through the Oracle JDBC jar, I found:
ojdbc6-unjar $ cat ./oracle/jdbc/defaultConnectionProperties.properties
# This properties file sets the default value for connection properties.
# Entries in this file override the predefined defaults as specified
# in the JavaDoc for oracle.jdbc.OracleConnection. These defaults are
# themselves overridden by any values set via -D which are overridden
# by values passed in the Properties argument to getConnection.
#
This bit and the Javadoc do a very bad job at explaining of how to derive the actual parameter name, but after many tries of various case styles, package names etc. I found this to be working:
JAVA_OPTS="-Doracle.jdbc.defaultRowPrefetch=1000" \
./activator -Dconfig.file=conf/xe.conf run
This will make boneCP use a reasonable fetch size without any code change.

How to use file-based config for Saml2SecurityTokenHandler?

Using Saml2SecurityTokenHandler to validate SAML2 bearer token from internal provider or from ACS. Able to programmatically configure the handler to validate just fine, but it doesn't seem to want to pick up configuration from the microsoft.IdentityModel section in my config file. Constructing a SecurityTokenHandlerCollectionManager seems to have no notion of the named configuration section either so I can't seem to use mySaml2SecurityTokenHandler .Configuration - mySecurityTokenHandlerCollectionManager["NAME"].Configuration.
Is there a good sample of setting this up somewhere?
To use file-based config, it turns out you simply rely on the FederatedAuthentication context, rather than explicitly constructing the Saml2SecurityTokenHandler:
var handlers = FederatedAuthentication.ServiceConfiguration.SecurityTokenHandlers;
var token = handlers.ReadToken(xmlReader);
var collection = handlers.ValidateToken(token);
This seems to be a known problem.
Have you tried FederatedClientCredentials --> SecurityTokenHandlerCollectionManager property --> SecurityTokenHandlerCollection --> replace the standard Saml2SecurityTokenHandler with whatever?

Unitils and DBMaintainer - how to make them work with multiple users/schemas?

I am working on a new Oracle ADF project, that is using Oragle 10g Database, and I am using Unitils and DBMaintainer in our project for:
updating the db structure
unittesting
read in seed data
read in test data
List item
In our project, we have 2 schemas, and 2 db users that have privilegies to connect to these schemas. I have them in a folder structure with incremental names and I am using the #convention for script naming.
001_#schemaA_name.sql
002_#schemaB_name.sql
003_#schemaA_name.sql
This works fine with ant and DBMaintainer update task, and I supply the multiple user names by configuring extra elements for the ant task.
<target name="create" depends="users-drop, users-create" description="This tasks ... ">
<updateDatabase scriptLocations="${dbscript.maintainer.dir}" autoCreateDbMaintainScriptsTable="true">
<database name="${db.user.dans}" driverClassName="${driver}" userName="${db.user.dans}" password="${db.user.dans.pwd}" url="${db.url.full}" schemaNames="${db.user.dans}" />
<database name="idp" driverClassName="${driver}" userName="${db.user.idp}"
password="${db.user.idp.pwd}" url="${db.url.full}" schemaNames="${db.user.idp}" />
</updateDatabase>
</target>
However, I cant figure out, how to make the DBMaintainer update task create the xsd schemas from my db schemas?
So, I decided to use Unitils, since its update creates xsd schemas.
I haven't found any description or documentation for the Unitils ant tasks - can anyone give some hints?
For the time being I have figured out to run Unitils by creating a Junit test, with #Dataset annotation. I can make it work with one schema, and one db user. But I am out of ideas how to make it work with multiple users?
Here is the unitils-local.properties setup I have:
database.url=jdbc\:oracle\:thin\:#localhost\:1521\:vipu
database.schemaNames=a,b
database.userName=a
database.password=a1
Can any of you guys give me a tip, how to make Unitils work with the second user/schema ??
I will be extremely gratefull for your help!
eventually I found a way to inject any unitil.properties of your choice --- by instantiating Unitils yourself!
You need a method that is evoked #BeforeClass, in which you perform something like the following:
#BeforeClass
public void initializeUnitils {
Properties properties;
...
// load properties file/values depending on various conditions
...
Unitils unitils = new Unitils();
unitils.init(properties);
Unitils.setInstance( unitils );
}
I choose the properties file depending on which hibernate configuration is loaded (via #HibernateSessionFactory), but there should be other options as well
I have figure out how to make dbmaintain and unitils work together on multi-database-user support, but the solution is a pure ant hack.
I have set up the configuration for dbmaintain, using multi-database-user support.
I have made a unitils-local.properties file with token keys for replacement.
The init target of my ant script is generating a new unitils-local.properties file, by replacing tokens for username/password/schema with values that are correct for the target envirnonment, and then copies it to the users home directory.
I have sorted the tests into folders, that are prefixed with the schema name
When unitils is invoked, it picks up the unitils-local.properties file just created by the ant script, and does its magic.
Its far from pretty, but it works.
Check out this link: http://www.dbmaintain.org/tutorial.html#From_Java_code
Specifically you may need to do something like:
databases.names=admin,user,read
database.driverClassName=oracle.jdbc.driver.OracleDriver
database.url=jdbc:oracle:thin://mydb:1521:MYDB
database.admin.username=admin
database.admin.password=adminpwd
database.admin.schemaNames=admin
database.user.userName=user
database.user.password=userpwd
database.user.schemaNames=user
database.read.userName=read
database.read.password=readpwd
database.read.schemaNames=read
Also this link may be helpful: http://www.dbmaintain.org/tutorial.html#Multi-database__user_support
I followed Ryan suggestion. I noticed couple changes when I debugged UnitilsDB.
Following is my running unitils-local.properties:
database.names=db1,db2
database.driverClassName.db1=oracle.jdbc.driver.OracleDriver
database.url.db1=jdbc:oracle:thin:#db1d.company.com:123:db1d
database.userName.db1=user
database.password.db1=password
database.dialect.db1=oracle
database.schemaNames.db1=user_admin
database.driverClassName.db2=oracle.jdbc.driver.OracleDriver
database.url.db2=jdbc:oracle:thin:#db2s.company.com:456:db2s
database.userName.db2=user
database.password.db2=password
database.dialect.db2=oracle
Make sure to use #ConfigurationProperties(prefix = "database.db1") to connecto to particular database in your test case:
#RunWith(UnitilsJUnit4TestClassRunner.class)
#ConfigurationProperties(prefix = "database.db1")
#Transactional
#DataSet
public class MyDAOTest {
..
}

Controlling WriteProfileString

Is it possible to specify the application name which is used by CWinApp::WriteProfileString()?
If I use CWinApp::SetRegistryKey to set the name of my company to "MyCompany", and I call AfxGetApp()->WriteProfileString in my application called "SomeApp", my string will be stored under the following registry key:
HKEY_CURRENT_USER\Software\MyCompany\SomeApp\...
The problem is that my users want to run multiple versions of SomeApp. So in order that the registry settings don't conflict I want to store them in keys like this:
HKEY_CURRENT_USER\Software\MyCompany\SomeApp 1.1\...
HKEY_CURRENT_USER\Software\MyCompany\SomeApp 2.0\...
etc.
I could replace all instances of WriteProfileString with my own function, but this would be quite difficult as it is used extensively in both our source code and some of the third-party libraries that we use.
Is there some way to force WriteProfileString to use a different string for the application name?
This code in the app constructor worked well:
free((void*)m_pszProfileName);
free((void*)m_pszRegistryKey);
m_pszRegistryKey = _tcsdup(L"nobugz");
m_pszProfileName = _tcsdup(L"myapp\\1.0");

Resources