Permalink
Browse files

Removing external tasks

  • Loading branch information...
1 parent ce9f3d1 commit 44459ebda8593b2d4fed41c7fc827c8d7ba2a867 @ayende ayende committed Feb 22, 2012
@@ -35,7 +35,7 @@ public byte[] AsBytes()
public static Task ToTask(string taskType, byte[] task)
{
- var type = typeof(Task).Assembly.GetType(taskType) ?? System.Type.GetType(taskType);
+ var type = typeof(Task).Assembly.GetType(taskType);
return (Task) new JsonSerializer().Deserialize(new BsonReader(new MemoryStream(task)), type);
}
@@ -1,31 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="MyTask.cs" company="Hibernating Rhinos LTD">
-// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-using Raven.Database.Indexing;
-using Raven.Database.Tasks;
-
-namespace Raven.Tests.ManagedStorage
-{
- public class MyTask : Task
- {
- public override bool TryMerge(Task task)
- {
- return true;
- }
-
- public override void Execute(WorkContext context)
- {
-
- }
-
- public override Task Clone()
- {
- return new MyTask
- {
- Index = Index,
- };
- }
- }
-}
@@ -5,6 +5,7 @@
//-----------------------------------------------------------------------
using System;
using Raven.Abstractions;
+using Raven.Database.Tasks;
using Xunit;
namespace Raven.Tests.ManagedStorage
@@ -18,7 +19,7 @@ public void CanCheckForExistanceOfTasks()
{
tx.Batch(accessor => accessor.Indexing.AddIndex("test", false));
tx.Batch(viewer => Assert.False(viewer.Staleness.IsIndexStale("test", null, null)));
- tx.Batch(mutator => mutator.Tasks.AddTask(new MyTask { Index = "test" }, SystemTime.Now));
+ tx.Batch(mutator => mutator.Tasks.AddTask(new RemoveFromIndexTask { Index = "test" }, SystemTime.Now));
tx.Batch(viewer => Assert.True(viewer.Staleness.IsIndexStale("test", null, null)));
}
}
@@ -30,12 +31,10 @@ public void CanCheckForExistanceOfTasksAfterTaskWasRemoved()
{
tx.Batch(accessor => accessor.Indexing.AddIndex("test", false));
tx.Batch(viewer => Assert.False(viewer.Staleness.IsIndexStale("test", null, null)));
- tx.Batch(mutator => mutator.Tasks.AddTask(new MyTask { Index = "test" }, SystemTime.Now));
- tx.Batch(viewer => Assert.True(viewer.Staleness.IsIndexStale("test", null, null)));
-
- int tasks = 0;
- tx.Batch(mutator => mutator.Tasks.GetMergedTask<MyTask>());
- Assert.Equal(1, tasks);
+ tx.Batch(mutator => mutator.Tasks.AddTask(new RemoveFromIndexTask { Index = "test" }, SystemTime.Now));
+ tx.Batch(viewer => Assert.True(viewer.Staleness.IsIndexStale("test", null, null)));
+
+ tx.Batch(mutator => Assert.NotNull(mutator.Tasks.GetMergedTask<RemoveFromIndexTask>()));
tx.Batch(viewer => Assert.False(viewer.Staleness.IsIndexStale("test", null, null)));
}
}
@@ -52,7 +51,7 @@ public void CanCheckForExistanceOfTasksWithCutOffs()
mutator.Indexing.AddIndex("test", false);
mutator.Indexing.UpdateLastIndexed("test", Guid.NewGuid(), cutoff);
});
- tx.Batch(mutator => mutator.Tasks.AddTask(new MyTask { Index = "test" }, SystemTime.UtcNow));
+ tx.Batch(mutator => mutator.Tasks.AddTask(new RemoveFromIndexTask { Index = "test" }, SystemTime.UtcNow));
tx.Batch(viewer => Assert.True(viewer.Staleness.IsIndexStale("test", null, null)));
tx.Batch(viewer => Assert.True(viewer.Staleness.IsIndexStale("test", cutoff.AddMinutes(1), null)));
tx.Batch(viewer => Assert.False(viewer.Staleness.IsIndexStale("test", cutoff.AddMinutes(-1), null)));
@@ -64,8 +63,8 @@ public void CanGetTask()
{
using (var tx = NewTransactionalStorage())
{
- tx.Batch(mutator => mutator.Tasks.AddTask(new MyTask { Index = "test" }, SystemTime.Now));
- tx.Batch(mutator => Assert.NotNull(mutator.Tasks.GetMergedTask<MyTask>()));
+ tx.Batch(mutator => mutator.Tasks.AddTask(new RemoveFromIndexTask { Index = "test" }, SystemTime.Now));
+ tx.Batch(mutator => Assert.NotNull(mutator.Tasks.GetMergedTask<RemoveFromIndexTask>()));
}
}
@@ -74,9 +73,9 @@ public void AfterGettingTaskOnceWillNotGetItAgain()
{
using (var tx = NewTransactionalStorage())
{
- tx.Batch(mutator => mutator.Tasks.AddTask(new MyTask { Index = "test" },SystemTime.Now));
- tx.Batch(mutator => Assert.NotNull(mutator.Tasks.GetMergedTask<MyTask>()));
- tx.Batch(mutator => Assert.Null(mutator.Tasks.GetMergedTask<MyTask>()));
+ tx.Batch(mutator => mutator.Tasks.AddTask(new RemoveFromIndexTask { Index = "test" }, SystemTime.Now));
+ tx.Batch(mutator => Assert.NotNull(mutator.Tasks.GetMergedTask<RemoveFromIndexTask>()));
+ tx.Batch(mutator => Assert.Null(mutator.Tasks.GetMergedTask<RemoveFromIndexTask>()));
}
}
@@ -85,11 +84,9 @@ public void CanMergeTasks()
{
using (var tx = NewTransactionalStorage())
{
- tx.Batch(mutator => mutator.Tasks.AddTask(new MyTask { Index = "test" }, SystemTime.Now));
- tx.Batch(mutator => mutator.Tasks.AddTask(new MyTask { Index = "test" }, SystemTime.Now));
- int tasks = 0;
- tx.Batch(mutator => Assert.NotNull(mutator.Tasks.GetMergedTask<MyTask>()));
- Assert.Equal(2, tasks);
+ tx.Batch(mutator => mutator.Tasks.AddTask(new RemoveFromIndexTask { Index = "test", Keys = {"a"}}, SystemTime.Now));
+ tx.Batch(mutator => mutator.Tasks.AddTask(new RemoveFromIndexTask { Index = "test", Keys = {"b"}}, SystemTime.Now));
+ tx.Batch(mutator => Assert.Equal(2, mutator.Tasks.GetMergedTask<RemoveFromIndexTask>().Keys.Count));
}
}
}
@@ -630,7 +630,6 @@
</Compile>
<Compile Include="ManagedStorage\Indexes.cs" />
<Compile Include="ManagedStorage\MappedResults.cs" />
- <Compile Include="ManagedStorage\MyTask.cs" />
<Compile Include="ManagedStorage\Queues.cs" />
<Compile Include="ManagedStorage\Storage.cs" />
<Compile Include="ManagedStorage\Tasks.cs" />

0 comments on commit 44459eb

Please sign in to comment.