dlnatoad icon indicating copy to clipboard operation
dlnatoad copied to clipboard

TreeWalkerTest and canonical file names

Open mapanett opened this issue 10 years ago • 4 comments

I was just trying to build dlnatoad on OS X and the TreeWalkerTest was failing.

What I found was that the TemporaryFolder rule was creating a folder under on /var/folder and on OS X /var is a symlink for /private/var

The TreeWalker at some point must resolve the paths to their canonical form and so the tests fails.

Adding a call .getCanonicalFile lets the test pass but I'm not sure if it's the best solution.

InOrder o = inOrder(hiker);
        o.verify(hiker).onDirWithFiles(this.tmp.getRoot().getCanonicalFile(),
                Arrays.asList(file1.getCanonicalFile(), file2.getCanonicalFile()));
        o.verify(hiker).onDirWithFiles(dir1.getCanonicalFile(), Arrays.asList(file3.getCanonicalFile(), file4.getCanonicalFile()));
        o.verifyNoMoreInteractions();

Here's a failure:

Argument(s) are different! Wanted:
hiker.onDirWithFiles(
    /var/folders/39/mvsf9mv13pn_8q87jkhff1000000gn/T/junit3130102322227212634,
    [/var/folders/39/mvsf9mv13pn_8q87jkhff1000000gn/T/junit3130102322227212634/file_1, /var/folders/39/mvsf9mv13pn_8q87jkhff1000000gn/T/junit3130102322227212634/File_2]
);
-> at com.vaguehope.dlnatoad.util.TreeWalkerTest.itWalksTree(TreeWalkerTest.java:44)
Actual invocation has different arguments:
hiker.onDirWithFiles(
    /private/var/folders/39/mvsf9mv13pn_8q87jkhff1000000gn/T/junit3130102322227212634,
    [/private/var/folders/39/mvsf9mv13pn_8q87jkhff1000000gn/T/junit3130102322227212634/file_1, /private/var/folders/39/mvsf9mv13pn_8q87jkhff1000000gn/T/junit3130102322227212634/File_2]
);
-> at com.vaguehope.dlnatoad.util.TreeWalker.walk(TreeWalker.java:63)
 <Click to see difference>

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at com.vaguehope.dlnatoad.util.TreeWalkerTest.itWalksTree(TreeWalkerTest.java:44)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

mapanett avatar Jun 27 '14 08:06 mapanett

I was vaguely aware of this issue, but since I do not use OSX that often never got round to digging into it. Interestingly it seems that someone else also had a go at working around this: https://github.com/vitalidze/dlnatoad/commit/f9a6574abc4c3d8cd848f0c85516da9925a9c550

I will have a look to see what seems the best fix.

haku avatar Jun 28 '14 06:06 haku

Rereading my code I have no idea why I ever thought I needed to use getCanonicalFile(). So I have deleted those calls. :) (though I do not have a OSX box to hand so can not test it right now)

haku avatar Jun 28 '14 06:06 haku

Thanks Alex,

I’ve been trying to setup an dlna server on my FreeBSD fileserver and so far yours is the only one that has worked. On my server I did get an error about

20:46:49.261 [ main] t.c.t.s.MulticastReceiver I Joining multicast group: /239.255.255.250:1900 on network interface: re0 An unhandled error occured. org.teleal.cling.transport.spi.InitializationException: Could not initialize MulticastReceiverImpl: java.net.SocketException: Invalid argument

To work around is either turn off IPv6 or run dlnatoat with -Djava.net.preferIPv4Stack=true

Also I noticed that cling seems to choosing a random port every time it starts. By default the FreeBSD firewall blocks all ports. I’m yet to looking into this issue.

Thanks again for dlnatoad.

Regards Matt

On 28 Jun 2014, at 4:41 pm, alex hutter [email protected] wrote:

Rereading my code I have no idea why I ever thought I needed to use getCanonicalFile(). So I have deleted those calls. :) (though I do not have a OSX box to hand so can not test it right now)

— Reply to this email directly or view it on GitHub.

mapanett avatar Jun 30 '14 22:06 mapanett

Hi Alex,

Configuring the port number was pretty straight forward. Just have to pass a UpnpServiceConfiguration to the UpnpService.

I’ll add it to a fork.

Regards Matt

On 1 Jul 2014, at 8:26 am, Matthew Panetta [email protected] wrote:

Thanks Alex,

I’ve been trying to setup an dlna server on my FreeBSD fileserver and so far yours is the only one that has worked. On my server I did get an error about

20:46:49.261 [ main] t.c.t.s.MulticastReceiver I Joining multicast group: /239.255.255.250:1900 on network interface: re0 An unhandled error occured. org.teleal.cling.transport.spi.InitializationException: Could not initialize MulticastReceiverImpl: java.net.SocketException: Invalid argument

To work around is either turn off IPv6 or run dlnatoat with -Djava.net.preferIPv4Stack=true

Also I noticed that cling seems to choosing a random port every time it starts. By default the FreeBSD firewall blocks all ports. I’m yet to looking into this issue.

Thanks again for dlnatoad.

Regards Matt

On 28 Jun 2014, at 4:41 pm, alex hutter [email protected] wrote:

Rereading my code I have no idea why I ever thought I needed to use getCanonicalFile(). So I have deleted those calls. :) (though I do not have a OSX box to hand so can not test it right now)

— Reply to this email directly or view it on GitHub.

mapanett avatar Jun 30 '14 22:06 mapanett