Compare commits

...

3 Commits

Author SHA1 Message Date
Justin Clark-Casey (justincc)
001bbb0b16 Fix a recent regression in e17392a where JsonSetValue() stopped working (probably other functions as well).
Fix is to call through to the no-arg constructor from the string constructor in JsonStore, which I suspect was just forgotten.
This was actually picked up by the TestJsonSetValue() regression test failing
But this isn't being run on jenkins due to the .net version issue.
This commit also puts the full stack trace in logged messages and makes these error level messages instead of info
2013-02-20 23:08:46 +00:00
Justin Clark-Casey (justincc)
365292e38f Add TestJsonWriteReadNotecard() regression test 2013-02-20 23:00:08 +00:00
Justin Clark-Casey (justincc)
fb2de29f77 Make json store tests operate on a single thread to ensure we don't run into any race related test failures in the future. 2013-02-20 22:59:38 +00:00
4 changed files with 72 additions and 20 deletions

View File

@@ -103,13 +103,6 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
return PathExpressionToKey(ParsePathExpression(path));
}
// -----------------------------------------------------------------
/// <summary>
///
/// </summary>
// -----------------------------------------------------------------
public JsonStore() : this("") {}
public JsonStore(string value)
{
m_TakeStore = new List<TakeValueCallbackClass>();

View File

@@ -93,12 +93,12 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
}
catch (Exception e)
{
m_log.ErrorFormat("[JsonStore] initialization error: {0}",e.Message);
m_log.Error("[JsonStore]: initialization error: {0}", e);
return;
}
if (m_enabled)
m_log.DebugFormat("[JsonStore] module is enabled");
m_log.DebugFormat("[JsonStore]: module is enabled");
}
// -----------------------------------------------------------------
@@ -191,7 +191,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
}
catch (Exception e)
{
m_log.InfoFormat("[JsonStore] Unable to initialize store from {0}; {1}",value,e.Message);
m_log.Error(string.Format("[JsonStore]: Unable to initialize store from {0}", value), e);
return false;
}
@@ -255,7 +255,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
}
catch (Exception e)
{
m_log.InfoFormat("[JsonStore] Path test failed for {0} in {1}; {2}",path,storeID,e.Message);
m_log.Error(string.Format("[JsonStore]: Path test failed for {0} in {1}", path, storeID), e);
}
return false;
@@ -288,7 +288,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
}
catch (Exception e)
{
m_log.InfoFormat("[JsonStore] Unable to assign {0} to {1} in {2}; {3}",value,path,storeID,e.Message);
m_log.Error(string.Format("[JsonStore]: Unable to assign {0} to {1} in {2}", value, path, storeID), e);
}
return false;
@@ -321,7 +321,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
}
catch (Exception e)
{
m_log.InfoFormat("[JsonStore] Unable to remove {0} in {1}; {2}",path,storeID,e.Message);
m_log.Error(string.Format("[JsonStore]: Unable to remove {0} in {1}", path, storeID), e);
}
return false;
@@ -354,7 +354,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
}
catch (Exception e)
{
m_log.InfoFormat("[JsonStore] unable to retrieve value; {0}",e.Message);
m_log.Error("[JsonStore]: unable to retrieve value", e);
}
return false;
@@ -393,7 +393,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
}
catch (Exception e)
{
m_log.InfoFormat("[JsonStore] unable to retrieve value; {0}",e.ToString());
m_log.Error("[JsonStore] unable to retrieve value", e);
}
cback(String.Empty);
@@ -432,7 +432,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
}
catch (Exception e)
{
m_log.InfoFormat("[JsonStore] unable to retrieve value; {0}",e.ToString());
m_log.Error("[JsonStore]: unable to retrieve value", e);
}
cback(String.Empty);

View File

@@ -54,6 +54,22 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
private MockScriptEngine m_engine;
private ScriptModuleCommsModule m_smcm;
[TestFixtureSetUp]
public void FixtureInit()
{
// Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
}
[TestFixtureTearDown]
public void TearDown()
{
// We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
// threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
// tests really shouldn't).
Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
}
[SetUp]
public override void SetUp()
{
@@ -85,7 +101,12 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
private object InvokeOp(string name, params object[] args)
{
return m_smcm.InvokeOperation(UUID.Zero, UUID.Zero, name, args);
return InvokeOpOnHost(name, UUID.Zero, args);
}
private object InvokeOpOnHost(string name, UUID hostId, params object[] args)
{
return m_smcm.InvokeOperation(hostId, UUID.Zero, name, args);
}
[Test]
@@ -184,11 +205,49 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
TestHelpers.InMethod();
// TestHelpers.EnableLogging();
UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ }");
int result = (int)InvokeOp("JsonSetValue", storeId, "Hello", "World");
int result = (int)InvokeOp("JsonSetValue", storeId, "Fun", "Times");
Assert.That(result, Is.EqualTo(1));
string value = (string)InvokeOp("JsonGetValue", storeId, "Fun");
Assert.That(value, Is.EqualTo("Times"));
}
/// <summary>
/// Test for reading and writing json to a notecard
/// </summary>
/// <remarks>
/// TODO: Really needs to test correct receipt of the link_message event. Could do this by directly fetching
/// it via the MockScriptEngine or perhaps by a dummy script instance.
/// </remarks>
[Test]
public void TestJsonWriteReadNotecard()
{
TestHelpers.InMethod();
TestHelpers.EnableLogging();
string notecardName = "nc1";
SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, TestHelpers.ParseTail(0x1));
m_scene.AddSceneObject(so);
UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello':'World' }");
// Write notecard
UUID writeNotecardRequestId = (UUID)InvokeOpOnHost("JsonWriteNotecard", so.UUID, storeId, "/", notecardName);
Assert.That(writeNotecardRequestId, Is.Not.EqualTo(UUID.Zero));
TaskInventoryItem nc1Item = so.RootPart.Inventory.GetInventoryItem(notecardName);
Assert.That(nc1Item, Is.Not.Null);
// TODO: Should probably independently check the contents.
// Read notecard
UUID receivingStoreId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello':'World' }");
UUID readNotecardRequestId = (UUID)InvokeOpOnHost("JsonReadNotecard", so.UUID, receivingStoreId, "/", notecardName);
Assert.That(readNotecardRequestId, Is.Not.EqualTo(UUID.Zero));
string value = (string)InvokeOp("JsonGetValue", storeId, "Hello");
Assert.That(value, Is.EqualTo("World"));
}

View File

@@ -85,7 +85,7 @@ namespace OpenSim.Tests.Common
public bool PostScriptEvent(UUID itemID, string name, object[] args)
{
throw new System.NotImplementedException ();
return false;
}
public bool PostObjectEvent(UUID itemID, string name, object[] args)