Hi Endre

Thanks for your inputs. I just tried the following and this seems to work.
I will mention steps of what I did, may be others find it useful

*src/main/resources/application.conf*

akka {
  event-handlers = ["akka.event.slf4j.Slf4jEventHandler"]
  loglevel = "INFO"
}

*src/test/resources/test.monitoring.conf*

include "application.conf"

akka.loggers = [akka.testkit.TestEventListener]

*Test*

public class TestTenantMonitorActor {

  private final Config sourceConfig =
ConfigFactory.load("test.monitoring.conf");
  private static ActorSystem system = null;

  @Before
  public void setUp() throws Exception {
    system = ActorSystem.create("system", sourceConfig);
  }


@Test
  public void testActorForNonExistentLocation() throws Exception {
    final Map<String, String> configValues =
Collections.singletonMap("tenant.assetsLocation",

"/non/existentLocation");
    final Config config = mergeConfig(configValues);
    System.out.println(config.getList("akka.loggers"));

    new JavaTestKit(system) {{
      assertEquals("system", system.name());

      final Props props = TenantMonitorActor.props(config);
      final ActorRef supervisor = system.actorOf(props, "supervisor");
      new EventFilter<Void>(DiskException.class) {

        @Override
        protected Void run() {
          supervisor.tell(new TenantMonitorMessage(), supervisor);
          return null;
        }

}.from("akka://system/user/supervisor/diskMonitor").occurrences(1).exec();

    }};
  }

  private TestActorRef<TenantMonitorActor> getTenantMonitorActor(final
Config config) {
    final Props props = TenantMonitorActor.props(config);
    return TestActorRef.create(system, props, testName.getMethodName());
  }

  private Config mergeConfig(final Map<String, String> testValues) {
    final Config baseConfig = ConfigFactory.parseMap(testValues);
    return baseConfig.withFallback(sourceConfig);
  }
}

Thanks for your help again, very much appreciated!

On Tue, May 5, 2015 at 4:14 AM, Akka Team <akka.offic...@gmail.com> wrote:

> Hi Harit,
>
> By default the config library only looks for files named
> "application.conf" or "reference.conf" files, see details here:
> https://github.com/typesafehub/config#standard-behavior
>
> You can either put a reference.conf in your test classpath that is only
> resolved in test scope, or alternatively, you can pass a Config object (can
> be loaded from any given file) to an ActorSystem explicitly (as an argument
> to the factory method).
>
> -Endre
>
> On Sun, May 3, 2015 at 5:15 AM, Harit Himanshu <
> harit.subscripti...@gmail.com> wrote:
>
>> As per docs
>> <http://doc.akka.io/docs/akka/snapshot/java/testing.html#akka-testkit>,
>> under (Expecting Log Messages)
>> ote
>>
>> Be sure to exchange the default logger with the TestEventListener in
>> your application.conf to enable this function:
>>
>>
>>    1. akka.loggers = [akka.testkit.TestEventListener]
>>
>>
>> So, this works well when I put it in application.conf.
>>
>> But since application.con is what gets shipped as application, do we
>> really want to keep this logger in application.conf?
>>
>> In order to separate this, I created another config called
>> test.monitoring.conf, which looks like
>>
>> include "application.conf"
>>
>> akka {
>>   loggers = [akka.testkit.TestEventListener]
>> }
>>
>>
>> But now when I run my test, they fail, even if in my test I can print
>> that this Logger is present
>>
>> SimpleConfigList(["akka.testkit.TestEventListener"])
>>
>>
>>
>> What's wrong with my approach?
>>
>> Thanks
>> + Harit Himanshu
>>
>> --
>> >>>>>>>>>> Read the docs: http://akka.io/docs/
>> >>>>>>>>>> Check the FAQ:
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Akka User List" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to akka-user+unsubscr...@googlegroups.com.
>> To post to this group, send email to akka-user@googlegroups.com.
>> Visit this group at http://groups.google.com/group/akka-user.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Akka Team
> Typesafe - Reactive apps on the JVM
> Blog: letitcrash.com
> Twitter: @akkateam
>
> --
> >>>>>>>>>> Read the docs: http://akka.io/docs/
> >>>>>>>>>> Check the FAQ:
> http://doc.akka.io/docs/akka/current/additional/faq.html
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "Akka User List" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/akka-user/wR4sLNMgNvs/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> akka-user+unsubscr...@googlegroups.com.
> To post to this group, send email to akka-user@googlegroups.com.
> Visit this group at http://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to