/*
* Copyright (C) 2012-2016 DuyHai DOAN
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package info.archinnov.achilles.it.bugs;
import static info.archinnov.achilles.embedded.CassandraEmbeddedConfigParameters.DEFAULT_CASSANDRA_EMBEDDED_KEYSPACE_NAME;
import java.util.Date;
import org.apache.commons.lang3.RandomUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;
import info.archinnov.achilles.generated.ManagerFactory;
import info.archinnov.achilles.generated.ManagerFactoryBuilder;
import info.archinnov.achilles.generated.manager.SimpleEntity_Manager;
import info.archinnov.achilles.internals.entities.SimpleEntity;
import info.archinnov.achilles.it.utils.CassandraLogAsserter;
import info.archinnov.achilles.junit.AchillesTestResource;
import info.archinnov.achilles.junit.AchillesTestResourceBuilder;
@RunWith(MockitoJUnitRunner.class)
public class ClassLevelTracing {
@Rule
public AchillesTestResource<ManagerFactory> resource = AchillesTestResourceBuilder
.forJunit()
.entityClassesToTruncate(SimpleEntity.class)
.truncateBeforeAndAfterTest()
.build((cluster, statementsCache) -> ManagerFactoryBuilder
.builder(cluster)
.withManagedEntityClasses(SimpleEntity.class)
.doForceSchemaCreation(true)
.withStatementsCache(statementsCache)
.withDefaultKeyspaceName(DEFAULT_CASSANDRA_EMBEDDED_KEYSPACE_NAME)
.build());
private SimpleEntity_Manager manager = resource.getManagerFactory().forSimpleEntity();
@Test
public void should_activate_tracing_programmatically() throws Exception {
//Given
Long id = RandomUtils.nextLong(0L, Long.MAX_VALUE);
CassandraLogAsserter logAsserter = new CassandraLogAsserter();
logAsserter.prepareLogLevel(SimpleEntity.class.getCanonicalName());
//When
manager
.crud()
.insert(new SimpleEntity(id, new Date(), "value"))
.withTracing()
.execute();
//Then
logAsserter.assertContains("Tracing for Query ID");
}
}