Skip to content
This repository
Browse code

Merge branch 'dev' of github.com:/EventStore/EventStore into dev

  • Loading branch information...
commit 1c4f72e366ff28f10668d2a3b00d0e2d1a7e646c 2 parents f0787cb + 226a6d4
Andrii Nakryiko authored November 12, 2012
24  src/EventStore/EventStore.Common/Log/LogManager.cs
@@ -27,15 +27,34 @@
27 27
 // 
28 28
 using System;
29 29
 using System.IO;
  30
+using System.Text;
30 31
 using EventStore.Common.Configuration;
31 32
 using EventStore.Common.Utils;
  33
+using NLog;
  34
+using NLog.LayoutRenderers;
32 35
 
33 36
 namespace EventStore.Common.Log
34 37
 {
  38
+    [LayoutRenderer("logsdir")]
  39
+    public class NLogDirectoryLayoutRendered : LayoutRenderer
  40
+    {
  41
+        protected override void Append(StringBuilder builder, LogEventInfo logEvent)
  42
+        {
  43
+            builder.Append(LogManager._logsDirectory);
  44
+        }
  45
+    }
  46
+
35 47
     public static class LogManager
36 48
     {
  49
+
  50
+        static LogManager()
  51
+        {
  52
+            NLog.Config.ConfigurationItemFactory.Default.LayoutRenderers.RegisterDefinition("logsdir", typeof(NLogDirectoryLayoutRendered));
  53
+        }
  54
+
37 55
         private static readonly ILogger GlobalLogger = GetLogger("GLOBAL-LOGGER");
38 56
         private static bool _initialized;
  57
+        internal static string _logsDirectory;
39 58
 
40 59
         public static string LogsDirectory
41 60
         {
@@ -43,7 +62,7 @@ public static string LogsDirectory
43 62
             {
44 63
                 if (!_initialized)
45 64
                     throw new InvalidOperationException("Init method must be called");
46  
-                return Environment.GetEnvironmentVariable(Constants.EnvVarPrefix + Constants.EnvVarLogsSuffix);
  65
+                return _logsDirectory;
47 66
             }
48 67
         }
49 68
 
@@ -72,8 +91,7 @@ public static void Init(string componentName, string logsDirectory)
72 91
 
73 92
         private static void SetLogsDirectoryInternal(string logsDirectory)
74 93
         {
75  
-            const string logsDirEnvVar = Constants.EnvVarPrefix + Constants.EnvVarLogsSuffix;
76  
-            Environment.SetEnvironmentVariable(logsDirEnvVar, logsDirectory, EnvironmentVariableTarget.Process);
  94
+            _logsDirectory = logsDirectory;
77 95
         }
78 96
 
79 97
         private static void SetComponentName(string componentName)
1  src/EventStore/EventStore.Core.Tests/Services/Storage/ReadIndexTestScenario.cs
@@ -93,7 +93,6 @@ public override void TestFixtureSetUp()
93 93
             TableIndex = new TableIndex(Path.Combine(PathName, "index"),
94 94
                                         () => new HashListMemTable(MaxEntriesInMemTable * 2),
95 95
                                         MaxEntriesInMemTable);
96  
-            TableIndex.Initialize();
97 96
 
98 97
             var reader = new TFChunkReader(Db, Db.Config.WriterCheckpoint);
99 98
             ReadIndex = new ReadIndex(new NoopPublisher(),
9  ...re.Core.Tests/Services/Storage/Transactions/when_rebuilding_index_for_partially_persisted_transaction.cs
@@ -40,7 +40,7 @@
40 40
 
41 41
 namespace EventStore.Core.Tests.Services.Storage.Transactions
42 42
 {
43  
-    [TestFixture, Ignore]
  43
+    [TestFixture]
44 44
     public class when_rebuilding_index_for_partially_persisted_transaction : ReadIndexTestScenario
45 45
     {
46 46
         public when_rebuilding_index_for_partially_persisted_transaction(): base(maxEntriesInMemTable: 10)
@@ -58,7 +58,6 @@ public override void TestFixtureSetUp()
58 58
             TableIndex = new TableIndex(Path.Combine(PathName, "index"),
59 59
                                         () => new HashListMemTable(maxSize: 2000),
60 60
                                         maxSizeForMemory: MaxEntriesInMemTable);
61  
-            TableIndex.Initialize();
62 61
 
63 62
             ReadIndex = new ReadIndex(new NoopPublisher(),
64 63
                                       2,
@@ -70,12 +69,6 @@ public override void TestFixtureSetUp()
70 69
             ReadIndex.Build();
71 70
         }
72 71
 
73  
-        public override void TestFixtureTearDown()
74  
-        {
75  
-            Thread.Sleep(500); // give chance to IndexMap to dump files
76  
-            base.TestFixtureTearDown();
77  
-        }
78  
-
79 72
         protected override void WriteTestScenario()
80 73
         {
81 74
             var begin = WriteTransactionBegin("ES", ExpectedVersion.Any);
24  src/EventStore/EventStore.Core/Index/TableIndex.cs
@@ -62,7 +62,9 @@ public class TableIndex : ITableIndex
62 62
         private long _prepareCheckpoint = -1;
63 63
 
64 64
         private volatile bool _backgroundRunning;
65  
-        private readonly ManualResetEvent _backgroundRunningEvent = new ManualResetEvent(true);
  65
+        private readonly ManualResetEventSlim _backgroundRunningEvent = new ManualResetEventSlim(true);
  66
+
  67
+        private bool _initialized;
66 68
 
67 69
         public TableIndex(string directory, 
68 70
                           Func<IMemTable> memTableFactory, 
@@ -87,6 +89,12 @@ public class TableIndex : ITableIndex
87 89
         public void Initialize()
88 90
         {
89 91
             //NOT THREAD SAFE (assumes one thread)
  92
+
  93
+            if (_initialized)
  94
+                throw new IOException("TableIndex is already initialized.");
  95
+            
  96
+            _initialized = true;
  97
+            
90 98
             CreateIfDoesNotExist(_directory);
91 99
 
92 100
             try
@@ -163,6 +171,7 @@ public void Add(long commitPos, uint stream, int version, long position)
163 171
                     _awaitingMemTables = newTables;
164 172
                     if (!_backgroundRunning)
165 173
                     {
  174
+                        _backgroundRunningEvent.Reset();
166 175
                         _backgroundRunning = true;
167 176
                         ThreadPool.QueueUserWorkItem(x => ReadOffQueue());
168 177
                     }
@@ -175,7 +184,6 @@ public void Add(long commitPos, uint stream, int version, long position)
175 184
 
176 185
         private void ReadOffQueue()
177 186
         {
178  
-            _backgroundRunningEvent.Reset();
179 187
             try
180 188
             {
181 189
                 while (true)
@@ -188,6 +196,7 @@ private void ReadOffQueue()
188 196
                         if (_awaitingMemTables.Count == 1)
189 197
                         {
190 198
                             _backgroundRunning = false;
  199
+                            _backgroundRunningEvent.Set(); 
191 200
                             return;
192 201
                         }
193 202
                         tableItem = _awaitingMemTables[_awaitingMemTables.Count - 1];
@@ -240,11 +249,6 @@ private void ReadOffQueue()
240 249
                 Log.ErrorException(exc, "Error in TableIndex.ReadOffQueue");
241 250
                 throw;
242 251
             }
243  
-            finally
244  
-            {
245  
-                _backgroundRunning = false;
246  
-                _backgroundRunningEvent.Set();
247  
-            }
248 252
         }
249 253
 
250 254
         private void ReclaimMemoryIfNeeded(List<TableItem> awaitingMemTables)
@@ -442,11 +446,11 @@ private static int GetMaxOf(List<IEnumerator<IndexEntry>> enumerators)
442 446
 
443 447
         public void ClearAll(bool removeFiles = true)
444 448
         {
445  
-            _awaitingMemTables = new List<TableItem> { new TableItem(_memTableFactory(), -1, -1) };
446  
-
447  
-            _backgroundRunningEvent.WaitOne(1000);
448 449
             //this should also make sure that no background tasks are running anymore
449 450
 
  451
+            if (!_backgroundRunningEvent.Wait(1000))
  452
+                throw new TimeoutException("Could not finish background thread in reasonable time.");
  453
+
450 454
             if (_indexMap != null)
451 455
             {
452 456
                 if (removeFiles)
3  src/EventStore/EventStore.Core/Messages/HttpClientMessageDto.cs
@@ -38,6 +38,7 @@ public static class HttpClientMessageDto
38 38
     {
39 39
         #region HTTP DTO
40 40
 
  41
+        [XmlType(TypeName = "event")]
41 42
         public class ClientEventText
42 43
         {
43 44
             public Guid EventId { get; set; }
@@ -75,6 +76,7 @@ public ClientEventText(Guid eventId, string eventType, byte[] data, byte[] metaD
75 76
             }
76 77
         }
77 78
 
  79
+        [XmlRoot(ElementName = "write-events")]
78 80
         public class WriteEventsText
79 81
         {
80 82
             public int ExpectedVersion { get; set; }
@@ -94,6 +96,7 @@ public WriteEventsText(int expectedVersion, ClientEventText[] events)
94 96
             }
95 97
         }
96 98
 
  99
+        [XmlRoot(ElementName = "read-event-result")]
97 100
         public class ReadEventCompletedText
98 101
         {
99 102
             public string EventStreamId { get; set; }
29  src/EventStore/EventStore.Core/Services/Transport/Http/AutoEventConverter.cs
@@ -101,17 +101,30 @@ private static HttpClientMessageDto.WriteEventsText LoadFromXml(string xml)
101 101
         {
102 102
             try
103 103
             {
104  
-                xml = xml.Replace("<Events>", string.Empty).Replace("</Events>", string.Empty)
105  
-                         .Replace("<write-events>", "<write-events xmlns:json='http://james.newtonking.com/projects/json'>")
106  
-                         .Replace("<event>", "<Events json:Array='true'>").Replace("</event>", "</Events>");
107 104
                 var doc = XDocument.Parse(xml);
108 105
 
109  
-                var version = doc.Descendants("ExpectedVersion").Single();
110  
-                version.Remove();
  106
+                XNamespace jsonNs = "http://james.newtonking.com/projects/json";
  107
+                XName jsonName = XNamespace.Xmlns + "json";
111 108
 
112  
-                var json = JsonConvert.SerializeXNode(doc, Formatting.None, true);
113  
-                var textEvents = JsonConvert.DeserializeObject<JObject>(json)["Events"].ToObject<HttpClientMessageDto.ClientEventText[]>();
114  
-                return new HttpClientMessageDto.WriteEventsText(int.Parse(version.Value), textEvents.ToArray());
  109
+                doc.Root.SetAttributeValue(jsonName, jsonNs);
  110
+
  111
+                var expectedVersion = doc.Root.Element("ExpectedVersion");
  112
+                var events = doc.Root.Descendants("event").ToArray();
  113
+
  114
+                foreach (var @event in events)
  115
+                {
  116
+                    @event.Name = "Events";
  117
+                    @event.SetAttributeValue(jsonNs + "Array", "true");
  118
+                }
  119
+
  120
+                doc.Root.ReplaceNodes(events);
  121
+
  122
+                foreach (var element in doc.Root.Descendants("Data").Concat(doc.Root.Descendants("Metadata")))
  123
+                    element.RemoveAttributes();
  124
+
  125
+                var json = JsonConvert.SerializeXNode(doc, Formatting.None, false);
  126
+                var textEvents = JsonConvert.DeserializeObject<JObject>(json)["write-events"]["Events"].ToObject<HttpClientMessageDto.ClientEventText[]>();
  127
+                return new HttpClientMessageDto.WriteEventsText(int.Parse(expectedVersion.Value), textEvents.ToArray());
115 128
             }
116 129
             catch (Exception e)
117 130
             {
2  src/EventStore/EventStore.Projections.Core/Services/Management/ManagedProjection.cs
@@ -402,7 +402,7 @@ private void WriteCompleted(ClientMessage.WriteEventsCompleted message, Action c
402 402
         private void Prepare(Action onPrepared)
403 403
         {
404 404
             if (!Enabled)
405  
-                throw new InvalidOperationException("Disable projection cannot be prepared");
  405
+                throw new InvalidOperationException("Disabled projection cannot be prepared");
406 406
 
407 407
             var config = CreateDefaultProjectionConfiguration(GetMode());
408 408
 
8  src/EventStore/EventStore.SingleNode/NLog.config
@@ -8,14 +8,14 @@
8 8
   <targets async="true">
9 9
     <target name="fileLog"
10 10
             xsi:type="File"
11  
-            fileName="${environment:variable=EVENTSTORE_LOGSDIR}/${shortdate:universalTime=true}/${environment:variable=EVENTSTORE_INT-COMPONENT-NAME}.log"
  11
+            fileName="${logsdir}/${shortdate:universalTime=true}/${environment:variable=EVENTSTORE_INT-COMPONENT-NAME}.log"
12 12
             layout="[PID:${pad:padCharacter=0:padding=2:inner=${processid}} ${date:universalTime=true:format=yyyy\.MM\.dd HH\:mm\:ss\.fff} ${level} ${logger} ${threadid}]${newline}${message}${onexception:${newline}EXCEPTION OCCURED:${newline}${exception:format=tostring:innerFormat=tostring:maxInnerExceptionLevel=20}}"/>
13 13
 
14 14
     <target name="errorFileLog" 
15 15
             xsi:type="FilteringWrapper"
16 16
             condition="length('${exception}')>0">
17 17
       <target xsi:type="File"
18  
-              fileName="${environment:variable=EVENTSTORE_LOGSDIR}/${shortdate:universalTime=true}/${environment:variable=EVENTSTORE_INT-COMPONENT-NAME}-err.log"
  18
+              fileName="${logsdir}/${shortdate:universalTime=true}/${environment:variable=EVENTSTORE_INT-COMPONENT-NAME}-err.log"
19 19
               layout="[PID:${pad:padCharacter=0:padding=2:inner=${processid}} ${date:universalTime=true:format=yyyy\.MM\.dd HH\:mm\:ss\.fff} ${level} ${logger} ${threadid}]${newline}${message}${onexception:${newline}EXCEPTION OCCURED:${newline}${exception:format=tostring:innerFormat=tostring:maxInnerExceptionLevel=20}}"/>
20 20
     </target>
21 21
 
@@ -32,12 +32,12 @@
32 32
 
33 33
     <target name="statsFileLog"
34 34
             xsi:type="File"
35  
-            fileName="${environment:variable=EVENTSTORE_LOGSDIR}/${shortdate:universalTime=true}/${environment:variable=EVENTSTORE_INT-COMPONENT-NAME}-stats.csv"
  35
+            fileName="${logsdir}/${shortdate:universalTime=true}/${environment:variable=EVENTSTORE_INT-COMPONENT-NAME}-stats.csv"
36 36
             layout="${message}"/>
37 37
 
38 38
     <target name="integrationOutputFileLog"
39 39
          xsi:type="File"
40  
-         fileName="${environment:variable=EVENTSTORE_LOGSDIR}/${shortdate:universalTime=true}/${environment:variable=EVENTSTORE_INT-COMPONENT-NAME}-perf-${environment:variable=EVENTSTORE_TC_RUN_NUMBER}.txt"
  40
+         fileName="${logsdir}/${shortdate:universalTime=true}/${environment:variable=EVENTSTORE_INT-COMPONENT-NAME}-perf-${environment:variable=EVENTSTORE_TC_RUN_NUMBER}.txt"
41 41
          layout="[${pad:padCharacter=0:padding=5:inner=${processid}},${pad:padCharacter=0:padding=2:inner=${threadid}},${date:format=yyyy\.MM\.dd HH\:mm\:ss\.fff}]${newline}${message}"/>
42 42
   </targets>
43 43
 
9  src/EventStore/EventStore.TestClient/Commands/WriteFloodHttpProcessor.cs
@@ -128,8 +128,8 @@ private void WriteFlood(CommandProcessorContext context, string eventStreamId, i
128 128
                                                                "DATA" + new string('*', 256),
129 129
                                                                "METADATA" + new string('$', 100))
130 130
                             });
131  
-                        var requestString = Codec.Json.To(write);
132  
-                        client.Post(url, requestString, Codec.Json.ContentType, succHandler, exc => 
  131
+                        var requestString = Codec.Xml.To(write);
  132
+                        client.Post(url, requestString, Codec.Xml.ContentType, succHandler, exc => 
133 133
                         {
134 134
                             context.Log.ErrorException(exc, "Error during POST.");
135 135
                             Interlocked.Increment(ref fail);
@@ -176,7 +176,10 @@ private void WriteFlood(CommandProcessorContext context, string eventStreamId, i
176 176
                 string.Format("{0}-{1}-{2}-failureSuccessRate", Keyword, clientsCnt, requestsCnt),
177 177
                 100*fail/(fail + succ));
178 178
 
179  
-            context.Success();
  179
+            if (succ < fail)
  180
+                context.Fail(reason:"Number of failures is greater than number of successes");
  181
+            else
  182
+                context.Success();
180 183
         }
181 184
     }
182 185
 }
5  src/EventStore/EventStore.TestClient/Commands/WriteFloodProcessor.cs
@@ -230,7 +230,10 @@ private void WriteFlood(CommandProcessorContext context, int clientsCnt, long re
230 230
                 string.Format("{0}-{1}-{2}-failureSuccessRate", Keyword, clientsCnt, requestsCnt),
231 231
                 100*fail/(fail + succ));
232 232
 
233  
-            context.Success();
  233
+            if (succ < fail)
  234
+                context.Fail(reason: "Number of failures is greater than number of successes");
  235
+            else
  236
+                context.Success();
234 237
         }
235 238
     }
236 239
 }
9  src/EventStore/EventStore.TestClient/Commands/WriteFloodWaitingHttpProcessor.cs
@@ -124,10 +124,10 @@ private void WriteFlood(CommandProcessorContext context, int clientsCnt, int req
124 124
                                                                "DATA" + new string('*', 256),
125 125
                                                                "METADATA" + new string('$', 100))
126 126
                             });
127  
-                        var request = Codec.Json.To(write);
  127
+                        var request = Codec.Xml.To(write);
128 128
                         client.Post(url, 
129 129
                                     request, 
130  
-                                    Codec.Json.ContentType,
  130
+                                    Codec.Xml.ContentType,
131 131
                                     succHandler, 
132 132
                                     exc => 
133 133
                                     {
@@ -176,7 +176,10 @@ private void WriteFlood(CommandProcessorContext context, int clientsCnt, int req
176 176
             PerfUtils.LogTeamCityGraphData(string.Format("{0}-latency-ms", Keyword),
177 177
                                            (int)(sw.ElapsedMilliseconds / requestsCnt));
178 178
 
179  
-            context.Success();
  179
+            if (succ < fail)
  180
+                context.Fail(reason: "Number of failures is greater than number of successes");
  181
+            else
  182
+                context.Success();
180 183
         }
181 184
     }
182 185
 }
5  src/EventStore/EventStore.TestClient/Commands/WriteFloodWaitingProcessor.cs
@@ -180,7 +180,10 @@ private void WriteFlood(CommandProcessorContext context, int clientsCnt, int req
180 180
             PerfUtils.LogTeamCityGraphData(string.Format("{0}-latency-ms", Keyword),
181 181
                                            (int) (sw.ElapsedMilliseconds/requestsCnt));
182 182
 
183  
-            context.Success();
  183
+            if (succ < fail)
  184
+                context.Fail(reason: "Number of failures is greater than number of successes");
  185
+            else
  186
+                context.Success();
184 187
         }
185 188
     }
186 189
 }
9  src/EventStore/EventStore.TestClient/Commands/WriteLongTermHttpProcessor.cs
@@ -192,10 +192,10 @@ public bool Execute(CommandProcessorContext context, string[] args)
192 192
                             "DATA" + dataResultingSize.ToString(" 00000 ") + new string('*', dataResultingSize),
193 193
                                     "METADATA" + new string('$', 100))
194 194
                             });
195  
-                        var request = Codec.Json.To(write);
  195
+                        var request = Codec.Xml.To(write);
196 196
                         client.Post(url, 
197 197
                                     request, 
198  
-                                    Codec.Json.ContentType,
  198
+                                    Codec.Xml.ContentType,
199 199
                                     succHandler, 
200 200
                                     exc =>
201 201
                                         {
@@ -253,7 +253,10 @@ public bool Execute(CommandProcessorContext context, string[] args)
253 253
                 string.Format("{0}-{1}-{2}-failureSuccessRate", Keyword, clientsCnt, requestsCnt),
254 254
                 100 * fail / (fail + succ));
255 255
 
256  
-            context.Success();
  256
+            if (succ < fail)
  257
+                context.Fail(reason: "Number of failures is greater than number of successes");
  258
+            else
  259
+                context.Success();
257 260
         }
258 261
     }
259 262
 }
5  src/EventStore/EventStore.TestClient/Commands/WriteLongTermProcessor.cs
@@ -250,7 +250,10 @@ public bool Execute(CommandProcessorContext context, string[] args)
250 250
                 string.Format("{0}-{1}-{2}-failureSuccessRate", Keyword, clientsCnt, requestsCnt),
251 251
                 100*fail/(fail + succ));
252 252
 
253  
-            context.Success();
  253
+            if (succ < fail)
  254
+                context.Fail(reason: "Number of failures is greater than number of successes");
  255
+            else
  256
+                context.Success();
254 257
         }
255 258
     }
256 259
 }

0 notes on commit 1c4f72e

Please sign in to comment.
Something went wrong with that request. Please try again.