Database Reference
In-Depth Information
-testPing
Implementation
The first of our test methods is also the simplest. We call the
-ping
method on
the server, and nothing else. We do not expect a return from the server at all.
This method causes a log statement to be generated on the server, allowing
us to watch the server and see that connections are in fact coming in. It also
keeps the testing simple. With this method, we can confirm that the Bonjour
service and the distributed objects are working properly without having to
wonder whether some other logic in some other part of our application is the
real source of a failure. If the ping is not getting through, we know either the
Bonjour service or the distributed objects are failing.
- (
void
)testPing
{
[server ping];
}
-testObjectFetch Implementation
The
-testObjectFetch
is the first complicated method that we are testing across the
distributed objects link. In this test, we construct an
NSPredicate
that we pass to
the server to be executed against the
NSManagedObjectContext
. As I mentioned, passing
the
NSManagedObjectContext
itself across distributed objects produced some terminal
exceptions within the Core Data stack itself, so we are avoiding this by performing
as much of the Core Data work as possible on the server. Here we are passing in
the name of the entity we want to search against and the
NSPredicate
. The server
returns an
NSArray
of the entities that fit the
NSPredicate
. One interesting thing to
note in this method is that we are not using the new
for
loop to access the returned
NSArray
. Since the
NSArray
is actually an
NSDistant
proxy for the
NSArray
on the server,
the newer fast enumeration does not handle it properly. Therefore, we need to
use the older
NSEnumerator
instead.
- (
void
)testObjectFetch
{
NSString *test = [GUID substringToIndex:3];
NSPredicate *predicate = nil;
predicate = [NSPredicate predicateWithFormat:@
"name contains[c] %@"
, test];
NSArray *results = [server objectsOfName:@
"Test"
withPredicate:predicate];
NSEnumerator *enumerator = [results objectEnumerator];
NSManagedObject *object;
while
(object = [enumerator nextObject]) {
[object setValue:GUID forKey:@
"name"
];
}
[self setFilteredObjects:results];
}