HHH-6271 Introducing Byteman in order to really test that a certain log message gets never called.
This commit is contained in:
parent
fa1183f3f9
commit
60c1b23c7b
19
build.gradle
19
build.gradle
|
@ -49,6 +49,7 @@ idea {
|
|||
slf4jVersion = '1.6.1'
|
||||
junitVersion = '4.10'
|
||||
h2Version = '1.2.145'
|
||||
bytemanVersion = '1.5.2'
|
||||
|
||||
libraries = [
|
||||
// Ant
|
||||
|
@ -93,12 +94,15 @@ libraries = [
|
|||
jcl: 'commons-logging:commons-logging:99.0-does-not-exist',
|
||||
|
||||
|
||||
junit: "junit:junit:${junitVersion}",
|
||||
jpa_modelgen: 'org.hibernate:hibernate-jpamodelgen:1.1.1.Final',
|
||||
shrinkwrap_api: 'org.jboss.shrinkwrap:shrinkwrap-api:1.0.0-beta-6',
|
||||
shrinkwrap: 'org.jboss.shrinkwrap:shrinkwrap-impl-base:1.0.0-beta-6',
|
||||
validator: 'org.hibernate:hibernate-validator:4.2.0.Final',
|
||||
h2: "com.h2database:h2:${h2Version}"
|
||||
junit: "junit:junit:${junitVersion}",
|
||||
byteman: "org.jboss.byteman:byteman:${bytemanVersion}",
|
||||
byteman_install: "org.jboss.byteman:byteman-install:${bytemanVersion}",
|
||||
byteman_bmunit: "org.jboss.byteman:byteman-bmunit:${bytemanVersion}",
|
||||
jpa_modelgen: 'org.hibernate:hibernate-jpamodelgen:1.1.1.Final',
|
||||
shrinkwrap_api: 'org.jboss.shrinkwrap:shrinkwrap-api:1.0.0-beta-6',
|
||||
shrinkwrap: 'org.jboss.shrinkwrap:shrinkwrap-impl-base:1.0.0-beta-6',
|
||||
validator: 'org.hibernate:hibernate-validator:4.2.0.Final',
|
||||
h2: "com.h2database:h2:${h2Version}"
|
||||
]
|
||||
|
||||
|
||||
|
@ -145,6 +149,9 @@ subprojects { subProject ->
|
|||
dependencies {
|
||||
compile( libraries.logging )
|
||||
testCompile( libraries.junit )
|
||||
testCompile( libraries.byteman )
|
||||
testCompile( libraries.byteman_install )
|
||||
testCompile( libraries.byteman_bmunit )
|
||||
testRuntime( libraries.slf4j_api )
|
||||
testRuntime( libraries.slf4j_log4j12 )
|
||||
testRuntime( libraries.jcl_slf4j )
|
||||
|
|
|
@ -23,19 +23,40 @@
|
|||
*/
|
||||
package org.hibernate.test.annotations.xml.ejb3;
|
||||
|
||||
import org.jboss.byteman.contrib.bmunit.BMRule;
|
||||
import org.jboss.byteman.contrib.bmunit.BMRules;
|
||||
import org.jboss.byteman.contrib.bmunit.BMUnitRunner;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.byteman.BytemanHelper;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@TestForIssue(jiraKey = "HHH-6271")
|
||||
@RunWith(BMUnitRunner.class)
|
||||
public class OrmVersion1SupportedTest extends BaseCoreFunctionalTestCase {
|
||||
@Test
|
||||
public void testOrm1Support() throws Exception {
|
||||
@BMRules(rules = {
|
||||
@BMRule(targetClass = "org.hibernate.internal.CoreMessageLogger_$logger",
|
||||
targetMethod = "parsingXmlError",
|
||||
helper = "org.hibernate.testing.byteman.BytemanHelper",
|
||||
action = "countInvocation()",
|
||||
name = "testOrm1Support"),
|
||||
@BMRule(targetClass = "org.hibernate.internal.CoreMessageLogger_$logger",
|
||||
targetMethod = "parsingXmlErrorForFile",
|
||||
helper = "org.hibernate.testing.byteman.BytemanHelper",
|
||||
action = "countInvocation()",
|
||||
name = "testOrm1Support")
|
||||
})
|
||||
public void testOrm1Support() {
|
||||
// need to call buildSessionFactory, because this test is not using org.hibernate.testing.junit4.CustomRunner
|
||||
buildSessionFactory();
|
||||
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Light light = new Light();
|
||||
|
@ -47,6 +68,8 @@ public class OrmVersion1SupportedTest extends BaseCoreFunctionalTestCase {
|
|||
assertEquals( 1, s.getNamedQuery( "find.the.light" ).list().size() );
|
||||
tx.rollback();
|
||||
s.close();
|
||||
|
||||
assertEquals( "HHH00196 should not be called", 0, BytemanHelper.getAndResetInvocationCount() );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,6 +3,9 @@ apply plugin: 'java'
|
|||
dependencies {
|
||||
compile project( ':hibernate-core' )
|
||||
compile "junit:junit:4.8.2"
|
||||
compile( libraries.byteman )
|
||||
compile( libraries.byteman_install )
|
||||
compile( libraries.byteman_bmunit )
|
||||
compile "com.experlog:xapool:1.5.0"
|
||||
compile ( "org.jboss.jbossts:jbossjta:4.15.1.Final" ) {
|
||||
transitive=false;
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.testing.byteman;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.jboss.byteman.rule.Rule;
|
||||
import org.jboss.byteman.rule.helper.Helper;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author Sanne Grinovero <sanne@hibernate.org> (C) 2011 Red Hat Inc.
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
public class BytemanHelper extends Helper {
|
||||
private static final Logger log = Logger.getLogger( BytemanHelper.class );
|
||||
|
||||
public static final AtomicInteger counter = new AtomicInteger();
|
||||
|
||||
protected BytemanHelper(Rule rule) {
|
||||
super( rule );
|
||||
}
|
||||
|
||||
public void sleepASecond() {
|
||||
try {
|
||||
log.info( "Byteman rule triggered: sleeping a second" );
|
||||
Thread.sleep( 1000 );
|
||||
}
|
||||
catch ( InterruptedException e ) {
|
||||
Thread.currentThread().interrupt();
|
||||
log.error( "unexpected interruption", e );
|
||||
}
|
||||
}
|
||||
|
||||
public void throwNPE(String message) {
|
||||
//Needed because of Bug BYTEMAN-173: can't simply inject a NPE from the rule
|
||||
throw new NullPointerException( message );
|
||||
}
|
||||
|
||||
public void countInvocation() {
|
||||
log.debug( "Increment call count" );
|
||||
counter.incrementAndGet();
|
||||
}
|
||||
|
||||
public static int getAndResetInvocationCount() {
|
||||
return counter.getAndSet( 0 );
|
||||
}
|
||||
}
|
|
@ -127,7 +127,7 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
|||
|
||||
@BeforeClassOnce
|
||||
@SuppressWarnings( {"UnusedDeclaration"})
|
||||
private void buildSessionFactory() {
|
||||
protected void buildSessionFactory() {
|
||||
// for now, build the configuration to get all the property settings
|
||||
configuration = constructAndConfigureConfiguration();
|
||||
serviceRegistry = buildServiceRegistry( configuration );
|
||||
|
|
Loading…
Reference in New Issue